給代碼<div id="zuo2">aa</div>加鼠標移入事件,
var oZuo = document.getElementById('zuo2');
完全正常
而給一組代碼加鼠標移入事件,
<div class="zuo2">aaaa<div>
<div class="zuo2">aabb<div>
<div class="zuo2">acca<div>
var oZuo = document.getElementsByClassName('zuo2');
浏覽器不響應
var oZuolist = document.getElementsByClassName('zuo2');
for(var i=0;i<oZuolist.length;i++){
oZuolist[i].onmouseover=function(){
//注意涉及到這個對象不能使用oZuolist[i],要用this代替
}
}