javascript中的this
<script type="text/javascript">
var person = {
name:"Kevin Yang",
sayHi:function(){
alert("你好,我是"+this.name);
}
}
setTimeout(person.sayHi,2000);
</script>
------解决方案--------------------this 指 调用者的对象
setTimeout(person.sayHi,2000);
换成
person.sayHi();
就能正确了。
------解决方案--------------------你这里 this 指的是 window 对象
------解决方案--------------------或者
<script type="text/javascript">
var person = {
name:"Kevin Yang",
sayHi:function(){
alert("你好,我是"+person .name);
}
}
setTimeout(person.sayHi,2000);
</script>
------解决方案--------------------楼主没有调用哪个函数,所以没有显示
------解决方案--------------------<script type="text/javascript">
var person = {
name:"Kevin Yang",
sayHi:function(){
alert("你好,我是"+this.name);
}
}
setTimeout(function(){person.sayHi()},2000);
</script>
------解决方案--------------------JScript code
var person = {
name:"Kevin Yang",
sayHi:function(){
alert("你好,我是"+this.name);
}
}
setTimeout("person.sayHi()",10);
------解决方案--------------------
JScript code
var person = {
name:"Kevin Yang",
sayHi:function(){
alert("你好,我是"+this.name);
}
}
setTimeout("person.sayHi()",10);
------解决方案--------------------
var person={
"SayHello":function(name){
alert(name);
}
}
调用:
person.SayHello("Test");