gpt4 book ai didi

javascript - 编辑 [href] http ://- https://jQuery 的开始

转载 作者:行者123 更新时间:2023-11-28 19:22:16 26 4
gpt4 key购买 nike

我正在创建一个 Chrome 扩展程序,用于检测 Google 搜索结果中的网址是否为 http://,如果是,则将其设为 https://

到目前为止我已经做到了。

$('a[href^="http://"]').attr('href', 'https://' + "a[href]");

任何帮助将不胜感激。谢谢:)

最佳答案

您需要将 http:// 替换为 https://

$('a[href^="http://"]').attr('href', function(i,oldhref){
oldhref.replace("http://","https://")
});

您还可以使用.each()来迭代它们:

$('a[href^="http://"]').each(function(){
$(this).attr('href', $(this).attr('href').replace("http://","https://"))
});

关于javascript - 编辑 [href] http ://- https://jQuery 的开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28626729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com