拆分中的变量不起作用 [英] Variable in split not work

查看:61
本文介绍了拆分中的变量不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在博客上显示评论者的唯一域名.但是我受到出现的变量的约束.

I want to display a unique domain name from commentators on my blog. But I am constrained by the variable that appears.

在这里,我做了两个这样的变量:

Here I made two variables like this:

<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>

<div class="container">
    <div class="comment_name">
        <a href="http://tes.wordpress.com">Sofyan</a>
        <div id="nameHost"></div>
    </div>
</div>

<div class="container">
    <div class="comment_name">
        <a href="http://tes.blogspot.com">Selfie</a>
        <div id="nameHost"></div>
    </div>
</div>

<script>
    var nameSite=[
        'wordpress',
        'blogspot'
    ];

    $(".comment_name a").attr('id', function(){
        return $(this).attr('href').split(".")[1];
    });


    for(var vol = 0; vol < nameSite.length; vol = vol+1){
        $("a[id='"+nameSite[vol]+"']").each(function(){
            $(this).closest(".container").find("#nameHost")
                .replaceWith("<div id='nameHost'>Host by: "+nameSite+" ..</div>");
        })
    }
</script>

但是,两者恰好都出现了.我希望这个网站有最好的解决方案.谢谢

However, that appears precisely both. I hope there is the best solution from this site. Thank you

推荐答案

for(var vol = 0; vol < nameSite.length; vol = vol+1){
    $("a[id='"+nameSite[vol]+"']").each(function(){
        $(this).closest(".container").find("#nameHost")
            .replaceWith("<div id='nameHost'>Host by: "+

                nameSite[vol] // I think this is your problem `vol`

            +" ..</div>");
    })
}

这篇关于拆分中的变量不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆