?????????var?tr?=?document.getElementsByTagName('tr');
????????????tr[0].onmouseover?=?function(){
??????????????tr[0].style.backgroundColor?=?'#ccc';?
????????????}
????????????tr[1].onmouseover?=?function(){
??????????????tr[1].style.backgroundColor?=?'#ccc';?
????????????}
????????????tr[2].onmouseover?=?function(){
??????????????tr[2].style.backgroundColor?=?'#ccc';?
????????????}上面的語句可以正常執(zhí)行,但是使用for循環(huán)的時候報錯。循環(huán)方式如下:?????????var?tr?=?document.getElementsByTagName('tr');
????????????for(var?i=0;i<tr.length;i++){
??????????????tr[i].onmouseover?=?function(){
????????????????tr[i].style.backgroundColor?=?'#ccc';?
??????????????}????????????
????????????}求指點
js 使用for 循環(huán)綁定onmouseover 事件出錯
馮春龍
2016-01-16 15:13:29