87,921
社区成员
发帖
与我相关
我的任务
分享
function foo( c )
{
this.cnt = c;
this.start = function()
{
setInterval( DoSomething, 1000 );
}
this.DoSomething = function()
{
this.cnt++; // just do something
}
}
var f1 = new foo( 1 );
f1.start();
var f2 = new foo( 100 );
f2.start();
var f3 = new foo( 243 );
f3.start();
<html>
<head><title>Timer In Class</title>
<script language="javascript">
function foo( id, val )
{
// this.obj = id;
window.document.getElementById(id).value = val;
this.start = function(id)
{
return function(){
setInterval(this.DoSomething, 1000 );//....
}
}(id);
this.DoSomething = function()
{
window.document.getElementById(id).value ++ ; // just do something
}
}
function OnBodyLoaded()
{
var f1 = new foo( "Text1", 1 );
f1.start();
var f2 = new foo( "Text2", 100 );
f2.start();
var f3 = new foo( "Text3", 243 );
f3.start();
}
</script>
</head>
<body onload="OnBodyLoaded();">
<input id="Text1" />
<input id="Text2" />
<input id="Text3" />
</body>
</html>
<html>
<head><title>Timer In Class</title>
<script language="javascript">
function foo( id, val )
{
this.obj = id;
var self = this;
window.document.getElementById(this.obj).value = val;
this.start = function()
{
setInterval(function(){self.DoSomething();}, 1000 );//....
}
this.DoSomething = function()
{
window.document.getElementById(this.obj).value ++ ; // just do something
}
}
function OnBodyLoaded()
{
var f1 = new foo( "Text1", 1 );
f1.start();
var f2 = new foo( "Text2", 100 );
f2.start();
var f3 = new foo( "Text3", 243 );
f3.start();
}
</script>
</head>
<body onLoad="OnBodyLoaded();">
<input id="Text1" />
<input id="Text2" />
<input id="Text3" />
</body>
</html>
function foo( id, val )
{
this.obj = id;
window.document.getElementById(this.obj).value = val;
this.start = function()
{
setInterval(this.DoSomething, 1000 );//....
}
this.DoSomething = function()
{
window.document.getElementById(this.obj).value ++ ; // just do something
}
}
var f1 = new foo( "Text1", 1 );
f1.start();
var f2 = new foo( "Text2", 100 );
f2.start();
var f3 = new foo( "Text3", 243 );
f3.start();
<html>
<head><title>Timer In Class</title>
<script language="javascript">
function foo( id, val )
{
this.obj = id;
window.document.getElementById(this.obj).value = val;
this.start = function()
{
setInterval(this.DoSomething, 1000 );//....
}
this.DoSomething = function()
{
window.document.getElementById(this.obj).value ++ ; // just do something
}
}
function OnBodyLoaded()
{
var f1 = new foo( "Text1", 1 );
f1.start();
var f2 = new foo( "Text2", 100 );
f2.start();
var f3 = new foo( "Text3", 243 );
f3.start();
}
</script>
</head>
<body onload="OnBodyLoaded();">
<input id="Text1" />
<input id="Text2" />
<input id="Text3" />
</body>
</html>
function foo( c )
{
this.cnt = c;
this.start = function()
{
setInterval(this.DoSomething, 1000 );//....
}
this.DoSomething = function()
{
this.cnt++; // just do something
}
}
var f1 = new foo( 1 );
f1.start();
var f2 = new foo( 100 );
f2.start();
var f3 = new foo( 243 );
f3.start();