<div?id="div1">
<input?type="submit"?value="選項(xiàng)卡1"?/>
<input?type="submit"?value="選項(xiàng)卡2"?/>
<input?type="submit"?value="選項(xiàng)卡3"?/>
<div?style="display:?block;">11111</div>
<div>222222</div>
<div>333333</div>
</div>
window.onload=function(){
var?oDiv=document.getElementById('div1');
var?aBtn=oDiv.getElementsByTagName('input');
var?aDiv=oDiv.getElementsByTagName('div');
for(var?i=0;i<aBtn.length;i++){
(function(){
aBtn[i].onclick?=?function?(){
alert(i);//為什么這里的i的值是3?,通過參數(shù)傳遞進(jìn)來的值不是只能是0、1、2么
}
})(i)
}
}
關(guān)于for循環(huán)中循環(huán)結(jié)束后值的問題
慕田峪8701529
2018-02-01 11:46:49