請問為什么不能這樣寫? 這個this代表的不是鼠標(biāo)點(diǎn)擊的這個Li 標(biāo)簽嗎?
window.onload=function (){
? ? //切換面板事件
? ? var oShow=document.getElementById('loginStateShow');
? ? var oTxt=document.getElementById('login2qq_state_txt');
? ? var oUl=document.getElementById('loginStatePanel');
? ? var oLis=document.getElementsByTagName('li');
? ? var oState=document.getElementById('loginState');
? ? oState.onclick=function() {
? ? ? ? oUl.style.display='block';
? ? }
? ? for(var i=0;i<oLis.length;i++){
? ? ? ? oLis[i].onmouseover=function(){
? ? ? ? ? ? this.style.background='#567';
? ? ? ? }
? ? ? ? oLis[i].onmouseout=function(){
? ? ? ? ? ? this.style.background='#FFF';
? ? ? ? }
? ? ? ? oLis[i].onclick=function(){
? ? ? ? ? ? oUl.style.display='none';
? ? ? ? ? ? oTxt.innerHTML=oLis[i].childNodes[1].innerHTML;
? ? ? ? ? ? var id=oLis[i].id;
? ? ? ? ? ? oShow.className='';
? ? ? ? ? ? oShow.className="login2qq_state_txt"+id;
? ? ? ? }
? ? }
? ??
? ??
}
2017-03-05
- -這么寫有報錯嗎,this還能規(guī)避閉包的問題,就是如果要給所有<li>綁事件,不如事件委托綁<ul>上去。