confirm()、setInterval()、setTimeout() 悠悠 2024-03-31 13:14 60阅读 0赞 ## confirm()、setInterval()、setTimeout() ## **学习路线**:[JavaScript基础语法(输出语句)][JavaScript]\->[JavaScript基础语法(变量)][JavaScript 1]\->[JavaScript基础语法(数据类型)][JavaScript 2]\->[JavaScript基础语法(运算符)][JavaScript 3]\->[JavaScript基础语法(流程控制语句)][JavaScript 4]\->[JavaScript基础语法(类型转换)][JavaScript 5]\->[JavaScript基础语法(函数)][JavaScript 6]\->[Array\_JavaScript][Array_JavaScript]\->[String\_JavaScript][String_JavaScript]\->[自定义对象\_JavaScript][JavaScript 7]\->[JavaScript\_BOM][JavaScript_BOM]\->[Window对象][Window]\->[confirm()、setInterval()、setTimeout()][confirm_setInterval_setTimeout]\->[History、Location][History_Location]\->[闪烁的灯泡][Link 1]\->[JavaScript\_DOM][JavaScript_DOM]\->[事件绑定(onclick,onfocus,onblur)][onclick_onfocus_onblur]\-> [事件绑定(onmouseout,onmouseover) ][onmouseout_onmouseover_]\->[事件绑定(onsubmit)表单提交 ][onsubmit_]\->[提交表单与验证表单案例 ][Link 2] **简介**:演示confirm()、setInterval()、setTimeout()的使用。 ### confirm() ### <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JavaScript演示</title> </head> <body> <script> // confirm(),点击确定按钮,返回true,点击取消按钮,返回false var flag = confirm("确认删除?"); document.write(flag); </script> </body> </html> **运行结果**: 选择确定 ![在这里插入图片描述][9f7001284b0645d8814b22c2a730475b.png] ![在这里插入图片描述][eb46d4d2f3c54a828e9b45b96a5942ec.png] ### setInterval(),setTimeout() ### `setTimeout(function,毫秒值)` : 在一定的时间间隔后执行一个function,只执行一次 `setInterval(function,毫秒值)` :在一定的时间间隔后执行一个function,循环执行 **通过一个案例讲解**: 屏幕上显示时间。 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JavaScript演示</title> </head> <body> <span id="time"></span> <script> setInterval( function show(){ var date = new Date(); var year = date.getFullYear(); var month = date.getMonth()+1; // month是从0开始的 所以需要+1 month = month<10?"0"+month:month; var week = date.getDay(); // 获取具体的天数取值范围为0~6 week = "星期"+"日一二三四五六".charAt(week); // 然后根据情况对应 var day = date.getDate(); day = day < 10 ? "0"+ day : day; // 三元运算符设置日期格式 var hour = date.getHours(); // 今天的小时 hour = hour < 10 ? "0" + hour : hour; var minutes = date.getMinutes(); // 今天的分钟 minutes = minutes < 10 ? "0" + minutes : minutes; var seconds = date.getSeconds(); // 今天的秒数 seconds = seconds < 10 ? "0" + seconds : seconds; var result = year+","+month+","+day+" "+week+" "+hour+":"+minutes+":"+seconds; // 最后拼接一个整的 document.getElementById("time").innerHTML = result; // 设置span中的内容 },1000); </script> </body> </html> **运行结果**: ![在这里插入图片描述][b97c920ceb2f4052b8aade3409d43475.png] [JavaScript]: https://blog.csdn.net/qq_51447496/article/details/128085137 [JavaScript 1]: https://blog.csdn.net/qq_51447496/article/details/128085348 [JavaScript 2]: https://blog.csdn.net/qq_51447496/article/details/128086148 [JavaScript 3]: https://blog.csdn.net/qq_51447496/article/details/128086681 [JavaScript 4]: https://blog.csdn.net/qq_51447496/article/details/128088817 [JavaScript 5]: https://blog.csdn.net/qq_51447496/article/details/128087248 [JavaScript 6]: https://blog.csdn.net/qq_51447496/article/details/128088986 [Array_JavaScript]: https://blog.csdn.net/qq_51447496/article/details/128089474 [String_JavaScript]: https://blog.csdn.net/qq_51447496/article/details/128089631 [JavaScript 7]: https://blog.csdn.net/qq_51447496/article/details/128089766 [JavaScript_BOM]: https://editor.csdn.net/md/?articleId=128095193 [Window]: https://blog.csdn.net/qq_51447496/article/details/128095300 [confirm_setInterval_setTimeout]: https://blog.csdn.net/qq_51447496/article/details/128103458 [History_Location]: https://blog.csdn.net/qq_51447496/article/details/128104240 [Link 1]: https://blog.csdn.net/qq_51447496/article/details/128095524 [JavaScript_DOM]: https://blog.csdn.net/qq_51447496/article/details/128104720 [onclick_onfocus_onblur]: https://blog.csdn.net/qq_51447496/article/details/128110532 [onmouseout_onmouseover_]: https://blog.csdn.net/qq_51447496/article/details/128112439 [onsubmit_]: https://blog.csdn.net/qq_51447496/article/details/128112553 [Link 2]: https://blog.csdn.net/qq_51447496/article/details/128112770 [9f7001284b0645d8814b22c2a730475b.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/31/04ef3ef168a04547bf0489c4ac89f5c5.png [eb46d4d2f3c54a828e9b45b96a5942ec.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/31/142a30c8c64747a9978be6cc34c07810.png [b97c920ceb2f4052b8aade3409d43475.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/31/9a16ced74b9c4dc5ba885d140baed809.png
还没有评论,来说两句吧...