亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jquery bind(click)傳參讓列表中每行綁定一個(gè)事件

 更新時(shí)間:2014年08月06日 11:37:32   投稿:whsnow  
用jquey bind 點(diǎn)擊事件時(shí),傳參不注意可能會(huì)導(dǎo)致點(diǎn)擊每一行都是顯示相同內(nèi)容的情況,下面有個(gè)示例,感興趣的朋友可以參考下

點(diǎn)擊列表中某行,彈出詳情的需求比較常見(jiàn)。用jquey bind 點(diǎn)擊事件時(shí),傳參不注意可能會(huì)導(dǎo)致點(diǎn)擊每一行都是顯示相同內(nèi)容的情況,這大多數(shù)是因?yàn)閭鲄](méi)注意引起的問(wèn)題。簡(jiǎn)易代碼如下:

for(var i=0;i<2;i++) { 
$("#b" + i).bind("click", {'bindText':bindText + i}, function(e){ 
butClick(e); 
}); 
}

測(cè)試代碼:

<html> 
<head> 
<script type="text/javascript" src="/jquery/jquery.js"></script> 

<script type="text/javascript"> 
$(document).ready(function(){ 
var bindText = 'AAA'; 
for(var i=0;i<2;i++) { 
$("#b" + i).bind("click", {'bindText':bindText + i}, function(e){ 
butClick(e); 
}); 
} 
}); 

function butClick(e) { 
alert(e.data.bindText); 
} 
</script> 
</head> 
<body> 
<button id="b0">請(qǐng)點(diǎn)擊這里0</button> 
<button id="b1">請(qǐng)點(diǎn)擊這里1</button> 
</body> 
</html>

相關(guān)文章

最新評(píng)論