this關(guān)鍵字指的是什么?如果不用this,應(yīng)該怎么寫?
? ?<script type="text/javascript">
?
window.onload=function(){
var box=document.getElementById('divselect'),
? ?title=box.getElementsByTagName('cite')[0],
? ?menu=box.getElementsByTagName('ul')[0],
? ?as=box.getElementsByTagName('a'),
? ? ? index=-1;
? ??
? ? // 點(diǎn)擊三角時(shí),顯示菜單
? ? title.onclick=function(e){
? ? ? // 執(zhí)行腳本
? ? ? ?e=e||window.event;//瀏覽器兼容
? ? ? ?menu.style.display='block';
? ? ? ?if(e.stopPropagation){
? ? ? ? ? e.stopPropagation();
? ? ? ?}else{
? ? ? ? e.cancleBubble=true;
? ? ? ?}
? ? }??
? ? ?
? ?// 滑過滑過、離開、點(diǎn)擊每個(gè)選項(xiàng)時(shí)
? ?for(var i=0;i<as.length;i++){?
? ? as[i].onmouseover=function(e){
? ? ? this.style.background='red';//this!這里this指什么,如果不用this關(guān)鍵字,應(yīng)該怎么寫?
? ? }?
? ? as[i].onmouseout=function(){
? ? ? this.style.background="#fff";
? ? }
?
? ? as[i].onclick=function(e){
? ? ?e=e||window.event;
? ? ?if(e.stopPropagation){
? ? ? e.stopPropagation();
? ? ?}else{
? ? ? e.cancleBubble=true;
? ? ?}
? ? ?menu.style.display='none';
? ? ?title.innerHTML=this.innerHTML;
? ? }
? ?}
?
?
?
? ?// 點(diǎn)擊頁面空白處時(shí),收回菜單
? ? document.onclick=function(){
? ? ? menu.style.display='none';
? ? }
?}
? ?</script>
2018-11-25
這里的this相當(dāng)于e.target或e.srcElement,自己給自己解答了,謝謝大家