国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

javascript - JQuery each traverses the A tag to obtain the href and takes the value of the attribute in the link and adds the attribute of A
伊謝爾倫
伊謝爾倫 2017-05-19 10:40:16
0
1
831

Original HTML code in the page:

<a class="item" >test1</a>
<a class="item" >test2</a>
<a class="item" >test3</a>

The final output effect I hope to achieve through jquery:

<a class="item" biz_itemid="1234" isconvert=1 >test1</a>
<a class="item" biz_itemid="12345" isconvert=1 >test2</a>
<a class="item" biz_itemid="432141" isconvert=1 >test3</a>

My current jQuery code:


function GetUrlParms(){
var args=new Object(); 
    var query=location.search.substring(1);//獲取查詢串 
    var pairs=query.split("&");//在逗號處斷開 
    for(var i=0;i<pairs.length;i++){ 
        var pos=pairs[i].indexOf('=');//查找name=value 
        if(pos==-1) continue;//如果沒有找到就跳過 
        var argname=pairs[i].substring(0,pos);//提取name 
        var value=pairs[i].substring(pos+1);//提取value 
        args[argname]=unescape(value);//存為屬性 
    }
return args;
}
 $(document).ready(
    $(".item").each(
        function(){
            var href = $(this).attr("href");
            var args = new Object();
            itemid = GetUrlParms("href");
            if(args["id"]!=undefined){
                var id = args["id"]
                $(this).attr('isconvert','1');
                $(this).attr('biz-itemid',"id");
            }
        }
    )
)

Please give me some advice! !

伊謝爾倫
伊謝爾倫

小伙看你根骨奇佳,潛力無限,來學(xué)PHP伐。

reply all(1)
淡淡煙草味
$(document).ready(function() {
    $(".item").each(
        function() {
            var href = $(this).attr("href"),
                itemid = href.match(/\?id=(\d+)/) ? href.match(/\?id=(\d+)/)[1] : 0;
            itemid && $(this).attr({'isconvert':'1','biz-itemid':itemid});
        }
    )
})

$(document).ready(function) should be a function

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template