2020
09-30
09-30
如何使用Javascript中的this关键字
一、基本的:functiondoSomething(){alert(this.id);}alert(window.doSomething);//证明了doSomething是属于window的doSomething();//undefinedwindow.onload=function(){document.getElementById("div2").onclick=doSomething;//div2document.getElementById("div3").onclick=function(){doSomething();}//undefined}1、对于doSomething这个函数:functiondoSomething(){alert(this.id);}这个函数是全局函数,这种全局函...
继续阅读 >