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

转载于:https://www.cnblogs.com/jintian/p/11107732.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值