Original HTML code in the page:
<a class="item" href="http://sample.com/do.php?id=1234">test1</a>
<a class="item" href="http://sample.com/do.php?id=12345">test2</a>
<a class="item" href="http://sample.com/do.php?id=432141">test3</a>
The final output effect I hope to achieve through jquery:
<a class="item" biz_itemid="1234" isconvert=1 href="http://sample.com/do.php?id=1234">test1</a>
<a class="item" biz_itemid="12345" isconvert=1 href="http://sample.com/do.php?id=12345">test2</a>
<a class="item" biz_itemid="432141" isconvert=1 href="http://sample.com/do.php?id=432141">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! !
$(document).ready(function) should be a function