我写了一个,但是总是提示找不到对象!
<script language=javascript>
function h(){
document.write('hello world!<br>');
setTimeout("h()",1000);
}
</script>
<body onload="h()">
<script language=javascript>
function h(){
document.write('hello world!<br>');
setTimeout("h()",1000);
}
</script>
<body onload="h()">
顺序问题把这段脚本放在<body>里面就行了
setTimeout(fun,timer)setTimeout不允许带参数的fun调用
function h(){
alert('hello world!<br>');
setTimeout(h, 1000);
}
</script>
<body onload="h()">
function h(){
text.innerHTML+='hello world!<br>';
setTimeout(h, 1000);
}
</script>
<body onload="h()">
<div id='text'></div>
<script language=javascript>
function h()
{
alert('hello world!');
setTimeout("h()",2000);
}
</script>
<body onload="h()">
</body>
clearTimeout()
为什么不使用该函数也能够顺利的进行循环?
一切搞定
我结合PHP做出来了一个抽奖程序!
2,每次setTimeout之前先clearTimeout,这个习惯要培养
3,为什么不用 += 呢
setTimeout可以用带参数的fun调用setTimeout(function(){yourfunctionname(obj);},1000)
//<![CDATA[
var iCount=0;
onload=function(){
//setInterval(function(){defaultStatus=iCount+=1}, 50);
var dt=new Date();
dt.setSeconds(dt.getSeconds()+30);
var oEleTimer=document.getElementById('timer');
fTimer(dt,oEleTimer, 50);
}
function fTimer(dtTimer, oEle, iMs){
var dt=new Date();
var iCk=((dtTimer.getTime()-dt.getTime())/1000).toFixed(3);
if(iCk<=0){
oEle.innerHTML='00.000';
return false;
} else {
oEle.innerHTML=iCk;
iTimer=setTimeout(function(){fTimer(dtTimer, oEle, iMs)},50);
}
} // shawl.qiu script
//]]>
</script>
</head>
<span id='timer'></span>
//<![CDATA[
onload=function(){
fTimer(30,'timer', 10);
}
function fTimer(iTimestamp, sId, iMs){
if(!(iTimestamp.constructor==Date)){
var sqTimeStamp=new Date();
sqTimeStamp.setSeconds(sqTimeStamp.getSeconds()+iTimestamp);
iTimestamp=sqTimeStamp;
}
if(typeof sId=='string'){
var oEle=document.getElementById(sId);
} else {
var oEle=sId;
}
var dt=new Date();
var iCk=((iTimestamp.getTime()-dt.getTime())/1000).toFixed(3);
if(iCk<=0){
oEle.innerHTML='00.000';
return false;
} else {
oEle.innerHTML=iCk;
iTimer=setTimeout(function(){fTimer(iTimestamp, oEle, iMs)},iMs);
}
} // end function fTimer // shawl.qiu script
//]]>
</script>
</head>
<span id='timer'></span>
//<![CDATA[
onload=function(){
fTimer(30,'timer', 10);
}
function fTimer(iTimestamp, sId, iMs){
if(!(iTimestamp.constructor==Date)){
var sqTimeStamp=new Date();
sqTimeStamp.setSeconds(sqTimeStamp.getSeconds()+iTimestamp);
iTimestamp=sqTimeStamp;
}
var tl=arguments.callee;
if(typeof sId=='string'){
var oEle=document.getElementById(sId);
} else {
var oEle=sId;
}
var dt=new Date();
var iCk=((iTimestamp.getTime()-dt.getTime())/1000).toFixed(3);
if(iCk<=0){
oEle.innerHTML='00.000';
return false;
} else {
oEle.innerHTML=iCk;
var iTimer=setTimeout(function(){tl(iTimestamp, oEle, iMs)},iMs);
}
} // end function fTimer // shawl.qiu script
//]]>
</script>
<span id='timer'></span>