Javascript 有人能纠正我吗

Javascript 有人能纠正我吗,javascript,list,Javascript,List,有人能帮我更正这个代码吗 缺少)参数列表之后。 <script> $(document).ready(function() { $(&quot;a&quot;).each(function() { var i = $(this).attr(&quot;href&quot;); var n = i.replace(http://www.p

有人能帮我更正这个代码吗 缺少)参数列表之后。

<script>
    $(document).ready(function() {           
        $(&quot;a&quot;).each(function() {
            var i = $(this).attr(&quot;href&quot;);            
            var n = i.replace(http://www.pantsumation.com, &quot;https://www.pantsumation.com&quot;);
            $(this).attr(&quot;href&quot;, function() {
                return n               
            })
        })           
    });
</script>

$(文档).ready(函数(){
$(“a”)。每个(函数(){
var i=$(this.attr(“href”);
var n=i.replace(http://www.pantsumation.com, "https://www.pantsumation.com");
$(this.attr(“href”,function()){
返回n
})
})           
});

谢谢,我不太擅长javascript,只是刚刚开始。

可能需要在第一个URL周围添加引号,如下所示:

$(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的链接。如果不想获得外部链接或类似链接,可以制作更精细的选择器

可能要先将您的代码包含在
标记中…上面的内容不包括抱歉。
“a”应该是
“a”
“href”
应该是
“href”
http://www.pantsumation.com, "https://www.pantsumation.com“
应该是
”http://www.pantsumation.com", "https://www.pantsumation.com“;
我已经替换了,并给了我以下信息:
未捕获类型错误:无法读取HtmlLanchoreElement处未定义的属性'replace'((索引):417)在Function.each(jquery.min.js?attredirects=0&d=1:2)在init.each(jquery.min.js?attredirects=0&d=1:2)在HTMLDocument处。((索引):415)在j(jquery.js:3148)在Object.fireWith[as resolveWith](jquery.js:3260)在Function.ready(jquery.js:3472)在HTMLDocument.J(jquery.js:3503)
让我试试看,现在它给了我这个:
未捕获类型错误:无法读取Function.each中未定义的属性“replace”。((索引):417)(jquery.min.js?attredirects=0&d=1:2)在init.each(jquery.min.js?attredirects=0&d=1:2)在HTMLDocument。((索引):415)在j(jquery.js:3148)在Object.fireWith[解析](jquery.js:3260)在Function.ready(jquery.js:3472)在HTMLDocument.j(jquery.js:3503)
有没有href的
吗?(答案是,是的,你有)那么我该如何修复它?