Original-HTML-Code auf der Seite:
<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>
Der endgültige Ausgabeeffekt, den ich durch jquery erreichen möchte:
<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>
Mein aktueller 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");
}
}
)
)
Bitte gebt mir einen Rat! !
$(document).ready(function)里面应是函数