【示例】
-
HTML
<form> <input type="button" value="Display timed alertbox!" onclick="timedMsg()"/> </form> <p>Click on the button above. An alert box will be displayed after 5 seconds.</p>
-
JS
var iSecond; function timedMsg(){ iSecond=Math.ceil((Math.random()*10)); var t=setTimeout("log()",iSecond*1000); } function log(){ $("#div-log").html($("#div-log").html()+"<p>时间延迟:"+iSecond+" seconds!"+"</p>"); }