分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

DOM confirm setTimeout url刷新

发布时间:2023-09-06 02:09责任编辑:郭大石关键词:urlDOM
console.log ????????????????输出框alert ??????????????????????弹出框confirm ????????????????????确认框 ?// URL和刷新location.href ??????????????获取URLlocation.href = "url" ??????重定向location.reload() ??????????重新加载 ?// 定时器setInterval ????????????????多次定时器clearInterval ??????????????清除多次定时器setTimeout ?????????????????单次定时器clearTimeout ???????????????清除单次定时器

setTimeout的作用,例如删除qq邮件时,顶部有个撤消五秒会消失。就是五秒后才真正删除,这期间你可以回收。setTimeout就是设置一个等待时长,这个时间过后,执行一次代码。

使用例子:

 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 ????<meta charset="UTF-8"> 5 ????<title>Title</title> 6 </head> 7 <body> 8 <input id="i1" type="text" value="test" /> 9 <label id="i2" onclick="Cancel();" style="background-color: red;"></label>10 <input onclick="Delete();" type="button" value="删除内容" />11 <input onclick="Flush();" type="button" value="刷新页面" />12 <script>13 ????function Delete() {14 ????????var v = confirm("are you really delete?");15 ????????var tag = document.getElementById(‘i2‘);16 ????????var i = 3; ?//三秒后删除17 ????????if (v == true){18 ????????????tag.style.display = ‘inline‘;19 ????????????tag.textContent = "点击[撤消]" + i;20 ????????????obj = setInterval(function () {21 ????????????????i--;22 ????????????????tag.textContent = "点击[撤消]" + i;23 ????????????},1000);24 ????????????obj1 = setTimeout(function () {25 ????????????????document.getElementById(‘i1‘).value = "";26 ????????????????clearInterval(obj); ???//倒计时过了,不再定时27 ????????????????tag.style.display = ‘none‘; ?//撤消时间已过,不显示撤消标签28 ????????????},3000);29 ????????}30 ????}31 ????function Flush() {32 ????????var url = location.href; //获取当前url33 ????????//location.href = "https://baidu.com"; ?//设置页面跳转34 ????????location.reload(); //刷新当前页面,也可以写成 location.href=location.href35 ????}36 ????function Cancel() {37 ????????clearTimeout(obj1);38 ????????clearTimeout(obj);39 ????????document.getElementById(‘i2‘).style.display = ‘none‘;40 ????}41 </script>42 </body>43 </html>
View Code

DOM confirm setTimeout url刷新

原文地址:https://www.cnblogs.com/alex-hrg/p/9454847.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved