87,904
社区成员
发帖
与我相关
我的任务
分享
function keepcheck()
{
document.write(".");
timer = setTimeout("keepcheck()",1000); //1s执行一次继续检查
}
keepcheck();
<!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" xml:lang="zh">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
div{width:100%;height:100px;border:solid 1px red;}
</style>
<script type="text/javascript">
var $ = function(id){ return document.getElementById(id);};
var timer;
window.onload = function(){
$("btn").onclick=function(){
if(timer&&this.value=="暂停")
clearInterval(timer);
else
timer = setInterval(print,1000);
this.value=this.value=="暂停"?"继续":"暂停";
}
}
function print(){
$("test").innerHTML=$("test").innerHTML+'.';
}
</script>
</head>
<body>
<div id="test"></div>
<input type="button" value="继续" id="btn" />
</body>
</html>
<span id="p"></span>
<script type="text/javascript">
var timer = null;
function keepcheck()
{
if(timer == null){clearTimeout(timer); timer = null;}
document.getElementById("p").innerHTML += ".";
timer = setTimeout(keepcheck, 1000); //1s执行一次继续检查
}
onload = function(){
keepcheck();
}
</script>
<script>
/*
function keepcheck()
{
document.write(".");
timer = setTimeout("keepcheck()",1000); //1s执行一次继续检查
}
keepcheck();*/
document.getElementById('test').innerHTML="1";
</script>
<body>
<div id="test"></div>
</body>
这样写为什么提示document.getElementById('test')为null