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