有人可以为我更正此代码: 参数列表后缺失。
<script>
$(document).ready(function() {
$("a").each(function() {
var i = $(this).attr("href");
var n = i.replace(http://www.pantsumation.com, "https://www.pantsumation.com");
$(this).attr("href", function() {
return n
})
})
});
</script>
谢谢,我不是那么擅长javascript并且刚开始。
答案 0 :(得分:1)
您可能需要在第一个网址周围添加引号,如下所示:
$(document).ready(function() {
$("a").each(function() {
var i = $(this).attr("href");
var n = i.replace("http://www.pantsumation.com", "https://www.pantsumation.com");
$(this).attr("href", function() {
return n;
})})});
更新
阅读您实际尝试做的事情而不是您提出的问题,您可能会发现在任何地方更换协议都会更容易:
$("a[href]").each(function(){
if( this.protocol === "http:")
this.protocol = "https:"
});
该选择器确保您只获得与其中的href链接。如果您不想获得外部链接或类似选项,您可以制作更精致的选择器。