<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<script type="text/javascript">
function test(name){
this.name = name;
}
test.prototype = {
age:0,
alertt:function(i){
var self = this;
document.write(this.name);
document.write(self.age);
alert(i);
},
dd:function(){
var self = this;
var i = 1;
this.alertt(this.name);
setInterval(function(){
i++;
this.alertt(i);
},2000)
}
}
var ff = new test('chaofan');
ff.dd();
</script>
</body>
</html>
为什么在
setInterval(function(){
i++;
this.alertt(i);
},2000)
处的this.alertt(i);
是未定义的,要怎么解决这个问题
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<script type="text/javascript">
function test(name){
this.name = name;
}
test.prototype = {
age:0,
alertt:function(i){
var self = this;
document.write(this.name);
document.write(self.age);
alert(i);
},
dd:function(){
var self = this;
var i = 1;
this.alertt(this.name);
setInterval(function(){
i++;
this.alertt(i);
},2000)
}
}
var ff = new test('chaofan');
ff.dd();
</script>
</body>
</html>
为什么在
setInterval(function(){
i++;
this.alertt(i);
},2000)
处的this.alertt(i);
是未定义的,要怎么解决这个问题
解决方案 »
- jquery的问题
- jquery html()方法中放入iframe,如何出现loading效果
- 没见过此写法 谁见过 指点一下 js
- 请教一个select的问题
- 已成功征集一软件名和域名,现再征收一关于"邮件集中管理"的软件名和域名.同样条件100分+300RMB,绝不食言
- 没有办法获得select中被选中option里的文字?
- 请教JAVASCRIPT里面对象的问题
- vbs里的timer()在javascript里应该是哪个函数???
- 关于刷新框架内页面的问题!
- 求助!如何为超连结的焦点换色编程?
- 如何优化JavaScript?怎样提高JS的性能?怎样预先加载JS代码?(急!在线等!)
- 关于js判断日期的问题不兼容
this.alertt is not a function意思this.alertt 不是一个方法~~
setInterval(function(){
i++;
self.alertt(i);
},2000)===========================
在function()中,this是没有定义的,应为function()并不是test的方法
你已经定义了 self=this;
把 dd:function(){}
内的 this.alertt(i) 改为 self.alertt(i)