dom04设置定时器

news/2024/7/7 9:44:50

定时器:

定时执行
var timerld=setInterval(code.interval);
clearInterval(timerld);
间隔时间执行,不是特别精确
//间歇定时器 setInterval(1回调函数,2时间间隔单位是毫秒);
间歇定时器

延迟执行
var timerld=setTimeout(code.interval);
clearTimeout(timerId);

//btn1设置延时定时器
//延时定时器 setTimeout(1回调函数2延迟的时间单位是毫秒)

var timerId=null;
var btn1=document.getElementById('btn1');
var btn2=document.getElementById('btn2');
btn1.onclick=function(){
    setTimeout(function () {
        console.log("boom");
    },3000);
};
btn2.onclick=function(){
    //清除定时器
    clearTimeout(timerId);
};

window.open(1地址,2哪里打开,3窗口的属性).

var win=window.open("http://www.baidu.com","_blank""width=200,height=200");
    btn.onclick=function(){
        //1地址,2哪里打开,3窗口的属性
        //window.open("http://www.baidu.com","_blank");//在新的空白窗口打开
        //window.open("http://www.baidu.com","_self");//在当前窗口打开
        window.open("http://www.baidu.com","_blank""width=200,height=200");//在新的空白窗口打开
    }
        win.close();//关闭当前窗口。

短信验证

<script>
//需求:点击按钮 按钮中的文字显示倒计时 倒计时后又恢复可以点击的状态
//代码提示:1绑定按钮,2给按钮注册点击事件,3点击后先禁用按钮disabled,
//4间歇定时器(倒计时,设置按钮中的value,定时器的回调函数中this指的是windows,)5时间不能写死(先用变量记录时间,每过一秒递减,)6判断倒计时的时间(到0秒后清除定时器,恢复可以点击的状态,里边文字变化)7num是全局变量,恢复num的值。
//
var timer=null;//这里为什么给定时器赋值个null啊?为什么不赋值其他?
var btn=document.getElementById('btn');
var num=5;
btn.onclick=function () {
    //console.dir(btn);
    this.disabled=true;//先禁用
    timer=setInterval(function () {//添加间歇定时器
        num--;
        btn.value=num+"秒之后再次点击";//秒数不能写死
        if (num===0) {
            clearInterval(timer);//清除定时器
            btn.value="点击发送验证码";
            num=5;
        };

    },1000);

}
</script>   

http://www.niftyadmin.cn/n/4828071.html

相关文章

C#正则表达式校验某个字符串是否是合格的email

C#正则表达式校验某个字符串是否是合格的email 可以借助正则表达式校验某个字符串是否是合规的电子邮箱。对于邮箱的正则表达式有严格的模式&#xff0c;如&#xff1a;^[a-zA-Z0-9_&*-](?:\\.[a-zA-Z0-9_&*-])*(?:[a-zA-Z0-9-]\\.)[a-zA-Z]{2,7}$ 对应的C#实现如下…

SQLException: Communications link failure

连接数据库时出现如下错误提示&#xff1a;SQLException: Communications link failureThe last packet sent successfully to the serverwas 0 milliseconds ago. The driver has not received any packets from theserver.附上部分代码段&#xff1a;publicstaticConnection …

dom04location对象,定时跳转及其它三个对象

location地址栏对象 window.location(地址&#xff0c;对应的是浏览器的地址栏&#xff09;。 location.href”网页地址/电子邮件等”&#xff1b; console.log(window.location.hash);//锚点&#xff0c;一般用于做单页面应用时比较常用。 console.log(window.location.ho…

暑期留校之iOS学习笔记之视图控制器(UI)

2015.8.18 <pre name"code" class"objc">//首先要导入头文件 #import "AppDelegate.h" #import "RootViewController.h"interface AppDelegate ()endimplementation AppDelegate- (BOOL)application:(UIApplication *)applicati…

dom04 移动盒子案例

移动盒子案例 鼠标经过长图往上走&#xff0c;鼠标经过长图往下走 <script>var timernull;var y0;//用变量记录top的初始值var picdocument.getElementById(pic);var goUpdocument.getElementById(goUp);var goDowndocument.getElementById(goDown);goUp.onmouseoverfu…

白驹过隙之大一总结

时间过得可真快&#xff0c;刚刚进入大学一幕幕还没退却&#xff0c;我已经度过了一年的大学生活了简单的谈谈我的大一都经历了哪些“小事”。 刚进入大学就是各种的 军训&#xff0c;教官很好&#xff0c;经常让我们休息&#xff0c;齐步走&#xff0c;踢正步&#xff0c;站…

包装类、object、单例模式、final、抽象类

/*包装类*/ /* byte Byte short Short int Integer long Long char Character float Float double Double boolean Boolean 基本数据和其包装类:作为成员变量时的默认初始值的差异: int -- Integer 0 null */ class WrapDemo { public s…

白驹过隙之大一总结第二话

话说母教义工吧&#xff0c;参加这个社团&#xff0c;完全因为初衷想报答社会&#xff0c;为社会增加正能量&#xff0c;一听是义工再加上是同班同学推荐拉进的&#xff0c;一想可能不错有好有个伴&#xff0c;后来发现&#xff0c;原来母教才是重点&#xff0c;第一次开会就懂…