87,922
社区成员
发帖
与我相关
我的任务
分享
<!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>js测试</title>
<style type="text/css">
#shit{
width:200px;
height:30px;
background-color:#999999;
border:1px solid #006699;
padding:5px;
color:#FFFFFF;
}
</style>
<script language="javascript" src="jquery.js"></script>
<script language="javascript">
function Class_test(){
this.value=1; //一个标记 用于说明问题所在
this.timeID="";
}
Class_test.prototype.shown=function(){
var now=new Date();
if (this.value!=1){
$("#shit").html(now.getHours()+":"+now.getMinutes()+":"+now.getSeconds()+" "+this.value);
}
else{
$("#shit").html(now.getYear()+"-"+now.getMonth()+"-"+now.getDay()+" "+this.value);
}
}
Class_test.prototype.shownTurn=function(){
this.timeID=setInterval(this.shown,1000);
}
$(document).ready(function(){
var aa=new Class_test();
aa.shownTurn(); //直接调用类方法 this.value无法按需求显示标记值
//var timeID=setInterval(aa.shown,1000); //问题同上 无法显示this.value的值
});
</script>
</head>
<body>
<div id="shit"></div>
</body>
</html>
Class_test.prototype.shownTurn=function(){
//this.timeID=setInterval(this.shown,1000);
this.timeID=setInterval((function(oThis){
return function(){
oThis.shown();
}
})(this),1000);
}