• js_计时器之setInterval


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <script type="text/javascript">
    var intervalId;
    window.onload = function () {
    //点击这个按钮,启动中间的计时器, setInterval计时器需要传递两个参数,一个是一个函数,一个是时间
    document.getElementById('btnStart').onclick = function () {
    //启动一个计时器
    intervalId = setInterval(function () {
    document.getElementById('txt1').value++;
    // //0.获取文本框对象
    // var txtObj = document.getElementById('txt1');
    // txtObj.value++;
    // // txtObj.value = ++txtObj.value;
    // // //每隔一秒钟执行一次这里的代码
    // // //让文本框中的数字累加
    // // //1.获取文本框中原来的值
    // // var v = txtObj.value;
    // // //2.加1
    // // v = parseInt(v) + 1; 将字符串转换成int类型的值
    // // //3.将新值再赋值给文本框
    // // txtObj.value = v;
    }, 1000);
    };

    //停止
    document.getElementById('btnStop').onclick = function () {
    clearInterval(intervalId);
    };
    };
    </script>
    </head>
    <body>
    <input type="text" name="name" value="0" id="txt1" />
    <input type="button" name="name" value="start" id="btnStart" />
    <input type="button" name="name" value="stop" id="btnStop" />
    </body>
    </html>

  • 相关阅读:
    ubuntu+VS code+launch.json+task.json
    C++——运行时类型识别RTTI
    C++——模板
    C++——class类和struct结构体的唯一区别
    C++——右值引用
    C++——智能指针
    身份证号码格式检测
    PHP获取图片主题颜色
    PHP 压缩图片质量
    redis3.2装完后 其它机子访问爆protocol error, got 'n' as reply type byte
  • 原文地址:https://www.cnblogs.com/wangjinya/p/10240019.html
Copyright © 2020-2023  润新知