日期:2014-05-16 浏览次数:20317 次
<html > <head > <script > function Test(){ var str=""; str+="Hello,"; str+="This is a Test! <br / >"; str+="I Love you; <br / >"; str+="I Love you,too!"; Test.num= Math.random(); document.all.p.innerHTML=str+"<br />"+Test.num; } </script > </head > <body onload="Test.timer=window.setInterval('Test()',1000)"> <span id="p" >12 </span > <input type="button" onClick="Stop();" value="stop" / > </doby > <script > function Stop() { clearInterval(Test.timer); alert(Test.num); } </script > </html >
------解决方案--------------------
<html >
<head >
<script >
var timeid;
function Test(){
var str="";
str+="Hello,";
str+="This is a Test! <br / >";
str+="I Love you; <br / >";
str+="I Love you,too!";
var num= Math.random();
p.innerHTML=str+" <br / > <br / >"+ " <p id=num >"+num+" </p >";
timeid = setTimeout( 'Test(); ',1000);
}
</script >
</head >
<body onload=Test(); >
<span id="p" >12 </span >
<input type="button" onClick="Stop();" value="stop" / >
</doby >
<script >
function Stop()
{
clearTimeout(timeid);
var num = document.getElementById("num").innerText;
alert(num);
}
</script >
</html >
是要这个样子的吗?