设定事件间隔和延迟

<script type="text/javascript">
var t=self.setInterval("clock()", 50);
function clock(){
    var time=new Date();
    document.getElementById("clock").value=time;
}

function timeMsg(){
    iSecond=Math.ceil((Math.random()*10));
    var t=setTimeout("log()", iSecond*1000);
}
function log(){
    $("#log").html("时间延迟:"+iSecond+"seconds!")
}
</script>
</head>
<body>
    <h2>jQuery设定时间间隔的方法</h2>
    <input type="text" id="clock" size="36"/>
    <button onclick="int=window.clearInterval(t)">stop interval</button>

    <h2>jQuery设定时间延迟的方法</h2>
    <form>
        <input type="button" value="Displayed timed alertbox!" onclick="timeMsg()"/>
    </form>
    <p>Click on the button above.An alert box will be displayed after 5 seconds.</p>
    <div id="log"></div>
</body>

setInterval(code,millisec[,”lang”]);
当中code參数表示要调用的函数或要运行的代码串,millisec參数表示周期性运行或调用code之间以毫秒计的时间间隔
setTimeout(code,millisec[,”lang”])
当中code參数表示要调用的函数或要运行的代码串,millisec參数表示在运行前需等待的毫秒数,code仅仅运行一次。若要多次调用,必须使用setInterval()或让code自身再次调用setTimeout()函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值