Javascrip 入门第三节课

 一、location对象

location.href  获取URL
location.href="URL" // 跳转到指定页面
location.reload() 重新加载页面

二、强弹出框

  alert('输入信息')

alert("你看到了吗?");

三、输入提示框

prompt("提示语“) //弹出输入框

四、计时器相关的函数 

setTimeout('js语句',毫秒) #过多少毫秒后执行前面的语句;
clearTimeout(setTimeout_variable) //参数为延时的变量名,取消延时设置
ID=setInterval("JS语句",时间间隔) ;//设置延时执行的程序
clearInterval(ID); //取消延时执行的程序
function foo()
    {
    for (let i=0;i<10;i++)
    {
    console.log(i);
    }
    }
setTimeout(foo,1000)

  定时器实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计时器</title>
    <script type="text/javascript">
        function timer(){
            var date=new Date();
            console.log(date);
            ret=document.getElementById('delay')
            ret.value=date;

        }

        var ID;
        function start_timer(){
        /*判断定时器是否已经启动,如果启动,重复按无效*/
            if (ID==undefined)            
            {
                timer();
                ID=setInterval(timer,1000);
            }            
        }
        function end_timer(){
            clearInterval(ID);
            //计时停止后,我们需要将ID的值还原为undefined,否则点击start无效
            ID=undefined;
        }
    </script>
</head>
<body>
    <input type="text" name="delaytime" id='delay' class="c1">
    <button onclick='start_timer()'>start</button><button onclick="end_timer()">end</button>
    
</body>
</html>
定时器代码示例

猜你喜欢

转载自www.cnblogs.com/angle6-liu/p/10168944.html