12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>dom</title>
- </head>
- <body>
- <button id="btn1">删除</button>
- <div id="printText">
- </div>
- <button id="start">开始</button>
- <button id="end">结束</button>
- </body>
- <script>
- //弹出框
- //alert("消息提示")
- document.getElementById("btn1").onclick = function (){
- //确认框
- let bool = confirm("确认删除吗?")
- if (bool){
- console.log("确认删除")
- }else{
- console.log("取消删除")
- }
- }
- //函数
- function print(){
- let element = document.getElementById("printText");
- //innerHtml 内容
- element.innerHTML = "";
- element.innerHTML = Math.random();
- }
- let flag
- document.getElementById("start").onclick = function (){
- //时间 循环执行 参数1 函数 参数2 时间
- //返回值 定时器标识
- flag = setInterval( print , 1000)
- }
- document.getElementById("end").onclick = function (){
- //清除定时器
- clearInterval(flag)
- }
- /*
- setInterval 定时器 执行多次
- 参数1 函数 参数2 执行周期
- clearInterval 清除定时器 标识 停止
- */
- //固定 执行时间 执行一次
- //参数1 函数
- //参数2 时间
- setTimeout(function (){
- console.log("执行一次")
- },5000)
- /*
- 练习
- 倒数10个数。
- 开始 按钮 10 9 8 7 1 .
- 输出 比赛结束。
- */
- </script>
- </html>
|