JS的window對象定時器


window.alert("hello") 提醒

ret=window.confirm() 確定返回true,取消返回false

window.promot() 接收用戶信息文本

open(url)  打開新的瀏覽器窗口

close()  關閉

setInterval(f,1000) 設定定時,每秒執行f()

new Date()  創建當前時間

clearInterval(setInterval(f,1000))  取消定時

setTimeout(f,1000)  一秒后執行f()

var clock  沒有var代表全局變量

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #id1{
            width: 200px;
            height: 50px;
        }
    </style>
</head>
<body>

<input type="text" id="id1" onclick="begin()">
<button onclick="end()">停止</button>


<script>

    function showTime() {
             var current_time=new Date().toLocaleString();
             var ele=document.getElementById("id1")
             ele.value=current_time
    }
    // var clock1;
    function begin() {
        // if(clock1==undefined){
            showTime();
          clock1=setInterval(showTime,1000)
        // }

    }

    function end() {
        clearInterval(clock1);
        clock1=undefined
    }


</script>
</body>
</html>
View Code


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM