設定事件間隔和延遲,設定事件間隔延遲

來源:互聯網
上載者:User

設定事件間隔和延遲,設定事件間隔延遲

<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()函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.