zoukankan      html  css  js  c++  java
  • js 琐碎

    1、setTimeout() 、setInterval()

    setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式。(即n毫秒后执行一次)

    setTimeout(code,n)

    setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式。(即每过n毫秒就执行一次)

    setInterval(code,millisec[,"lang"])


    setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭。由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的参数。
    eg: var timer = setInterval(function() {}, 1000);
       clearInterval(timer);//函数停止执行
    

      

    2、获取验证码,倒计时60秒

    <input type="button" id="btn" value="免费获取验证码" /> 
    <script type="text/javascript"> 
    var wait=60; 
    function time(o) { 
    if (wait == 0) { 
    o.removeAttribute("disabled"); 
    o.value="免费获取验证码"; 
    wait = 60; 
    } else { 
    o.setAttribute("disabled", true); 
    o.value="重新发送(" + wait + ")"; 
    wait--; 
    setTimeout(function() { 
    time(o) 
    }, 
    1000) 
    } 
    } 
    document.getElementById("btn").onclick=function(){time(this);}
    

      

  • 相关阅读:
    scott登录查询常用语句
    Oracle服务端及客户端安装
    SVN简单使用
    dos命令--查询进程
    第二周学习总结
    第一周学习总结
    虚拟机安装教程及网络连接方式的解释
    两天学习总结
    方差
    thinkphp 总结 转
  • 原文地址:https://www.cnblogs.com/shueixue/p/5777110.html
Copyright © 2011-2022 走看看