一、location对象
location.href 获取当前网页的URL
location.search() 获取?之后的请求信息
location.href="URL" // 跳转到指定页面
location.reload() 重新加载页面
二、强弹出框
alert('输入信息')
alert("你看到了吗?");
三、输入提示框
prompt("提示语“) //弹出输入框
四、计时器相关的函数
setTimeout('js语句',毫秒) #过多少毫秒后执行前面的语句;
clearTimeout(setTimeout_variable) //参数为延时的变量名,取消延时设置
ID=setInterval("JS语句",时间间隔) ;//设置每隔多少时间执行一次js语句;
clearInterval(ID); //取消延时执行的程序
function foo() { for (let i=0;i<10;i++) { console.log(i); } } setTimeout(foo,1000)
定时器实例
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<!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>