var name="全局";
function getName(){
var name="局部";
return this.name;
};
alert(getName());
alert(getName());
var name="全局";
var xpg={
name:"局部",getName:function(){
return this.name;
}
};
alert(xpg.getName());
alert(xpg.getName());
var someone = {
name: "Bob",showName: function(){
alert(this.name);
}
};
var other = {
name: "Tom",showName: someone.showName
}
other.showName();
var name="全局";
var xpg={
name:"局部",getName:function(){
return function(){
return this.name;
};
}
};
alert(xpg.getName()());
function (){
return this.name;
};
var name="全局";
var xpg={
name:"局部",getName:function(){
var that=this;
return function(){
return that.name;
};
}
};
alert(xpg.getName()());
alert(xpg.getName());
function Person(__name){
this.name = __name;
}
Person.prototype.show = function(){
alert(this.name);
}
var Bob = new Person("Bob");
Bob.show();
var name="全局";
var xpg={
name:"局部"
};
function getName(){
alert(this.name);
}
getName(xpg);
getName.call(xpg);
getName.call();
getName(xpg);
getName.call(xpg);
var name = "window";
var Bob = {
name: "Bob",showName: function(){
eval("alert(this.name)");
}
};
Bob.showName();
var name = "Tom";
var Bob = {
name: "Bob",show: function(){
alert(this.name);
}
}
var show = Bob.show;
show();
var name = "window";
var Bob = {
name: "Bob",showName: function(){
alert(this.name);
}
};
var Tom = {
name: "Tom",showName: function(){
var fun = Bob.showName;
fun();
}
};
Tom.showName();
var name = "Bob";
var nameObj ={
name : "Tom",showName : function(){
alert(this.name);
},waitShowName : function(){
setTimeout(this.showName,1000);
}
};
nameObj.waitShowName();
<input id="btnTest" type="button" value="提交" onclick="alert(this.value))" />
<script type="text/javascript">
function thisTest(){
alert(this.value);
}
</script>
<input id="btnTest" type="button" value="提交" onclick="thisTest()" />
<input id="btnTest" type="button" value="提交" />
<script type="text/javascript">
function thisTest(){
alert(this.value);
}
document.getElementById("btnTest").onclick=thisTest;
</script>
document.getElementById("domID").onclick=thisTest
<input id="btnTest1" type="button" value="提交1" onclick="thisTest()" />
<input id="btnTest2" type="button" value="提交2" />
<script type="text/javascript">
function thisTest(){
this.value="提交中";
}
var btn=document.getElementById("btnTest1");
alert(btn.onclick);
var btnOther=document.getElementById("btnTest2");
btnOther.onclick=thisTest;
alert(btnOther.onclick);
</script>
function onclick(){
thisTest()
}
function thisTest(){
this.value="提交中";
}
<input id="btnTest1" type="button" value="提交1" onclick="thisTest(this)" />
<input id="btnTest2" type="button" value="提交2" onclick="thisTest(this)" />
<input id="btnTest3" type="button" value="提交3" onclick="thisTest(this)" />
<input id="btnTest4" type="button" value="提交4" onclick="thisTest(this)" />
<script type="text/javascript">
function thisTest(obj){
alert(obj.value);
}
</script>
var EventUtil = new eventManager();
function eventManager() {
this.addEvent = function(oDomElement,oEventType,oFunc) {
if (oDomElement.attachEvent) {
oDomElement.attachEvent("on" + oEventType,oFunc);
}
else if (oDomElement.addEventListener) {
oDomElement.addEventListener(oEventType,oFunc,false);
}
else {
oDomElement["on" + oEventType] = oFunc;
}
}
this.removeEvent = function(oDomElement,oFunc) {
if (oDomElement.detachEvent) {
oDomElement.detachEvent("on" + oEventType,safari等
else if (oDomElement.removeEventListener) {
oDomElement.removeEventListener(oEventType,false);
}
else {
oDomElement["on" + oEventType] = null;
}
}
}