setTimeout和setInterval函数的试用

本文介绍了一个网页实时显示当前时间和自动更新功能,包括时间显示、页面跳转计时器、文本输入框控制按钮状态等。通过JavaScript实现定时任务、事件监听和页面元素操作,展示了网页动态交互的基本原理。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>时间</title>
<script type="text/javascript">
var i=5;
var d=null;
var ttt=null;//页面跳转
function test(){

if(i>0)
document.getElementById("b").value=i;
else{
clearInterval(d) ;
document.getElementById("b").disabled=false;
document.getElementById("b").value='提交';
}
--i;
}
var t=null;
function but(type){
var now=new Date();
var year=now.getYear();
var month=now.getMonth();
var date=now.getDate();
var day=now.getDay();
var hour=now.getHours();
var minu=now.getMinutes();
var sec=now.getSeconds();
var week;
month=month+1;
if(month<10) month="0"+month;
if(date<10) date="0"+date;
if(hour<10) hour="0"+hour;
if(minu<10) minu="0"+minu;
if(sec<10) sec="0"+sec;

switch (day){
case 1:
week="星期一";
break;
case 2:
week="星期二";
break;
case 3:
week="星期三";
break;
case 4:
week="星期四";
break;
case 5:
week="星期五";
break;
case 6:
week="星期六";
break;
default:
week="星期天"
break;
}
var q=now.getMilliseconds();
if(q<10)
{
q="00"+now.getMilliseconds();
}
if(q>=10 && q<100)
{
q="0"+now.getMilliseconds();
}
var time="";
time='现在时间:'+year+"年"+month+"月"+date+"日 "+week+" "+hour+":"+minu+":"+sec+":"+q;
if(type=='but'){
document.getElementById("i").value=time;
t=setTimeout("but('but')",100);
}
if(type=='auto'){
var div=document.getElementById("d");
div.innerHTML="<span style='color:red'>"+time+"</span>";
}


}
var si=null;
function run(){
si=setInterval("but('auto')",100);
d=setInterval("test()",1000);
ttt=setInterval("goTo()",1000);
}
function end(){
clearInterval(si) ;
}
function endbut(){
clearTimeout(t) ;
}
////页面跳转js
var tt=5;
function goTo(){

var t1=document.getElementById("t1");
t1.innerHTML="<span style='color:red'>"+tt+"</span>";
var t2=document.getElementById("t2");
var n="";
var ii=0
for(ii=0;ii<tt;ii++){
n+='*';
}
t2.innerHTML="<span style='color:blue;font-size:30px;vertical-align:middle;'>"+n+"</span>";
tt--;

if(tt<0)clearInterval(ttt) ;
}


</script>
</head>

<body onload="run(); ">
<label>自动运行的时间</label><br>
<div id="d" style="float: left;"></div><div style="float: left;"><input type="button" name="stop" value="stop" onclick="return end();"/><input type="button" name="stop" value="start" onclick="return run();"/></div>
<div style="clear: both;">==================================================================</div>
<label>代开始停止按钮的时间</label><br>
<div><input type="text" id="i" name="n" size="50"/><input type="button" value="start" onclick="return but('but');"/>
<input type="button" name="stop" value="stop" onclick="return endbut();"/></div>
<div>=============================================================</div>
<label>提交按钮等待5秒可用</label><br>
<input type="button" id="b" value="提交" disabled="disabled" style="height: 25px;width: 50px;"/>
<div style="clear: both;"><div>=============================================================</div>
<label>页面跳转时间等待</label><br>
页面正在跳转,<label id="t1"></label>请稍后<label id="t2" style="vertical-align:text-bottom;"></label>
<div style="clear: both;">==================================================================</div>

</body>
</html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link id="favicon" rel="icon" type="image/svg+xml" href="https://csr-pictures.oss-cn-hangzhou.aliyuncs.com/image/favicon.ico" /> <meta name="author" content="yx" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>福客AI官网-AI智能客服机器人_电商客服机器人</title> <meta name="keywords" content="福客AI,AI客服机器人,智能客服机器人,电商客服机器人,freecallAI" /> <meta name="description" content="福客AI更智能更提效的AI客服机器人,基于顶尖大语言模型,并通过自研多智能体协同算法与电商场景定向训练,助力全球电商卖家实现降本增效与客户体验的双重提升。" /> <meta property="og:title" content="福客AI官网-AI智能客服机器人_电商客服机器人" /> <meta property="og:image" content="https://csr-pictures.oss-cn-hangzhou.aliyuncs.com/download/logo.png" /> <script type="module" crossorigin src="/assets/index-BZjTrSva.js"></script> <link rel="stylesheet" crossorigin href="/assets/index-5-sMHqH5.css"> </head> <body> <div id="app"></div> </body> </html>他这个也是这样啊,为什么我的就不被录入。<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/static/voragowebsite/css/favicon-D0wM-rMv.ico" /> <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no" /> <meta name="baidu-site-verification" content="codeva-yh2DGAowcX" /> <meta name="description" content="电商AI超级智能客服,MAT多模态智能体,基于 DeepSeek 大模型构建,一键部署、全平台覆盖、聚合多店铺同步接待与自定义话术库,为电商及企业级用户提供解决方案,7*24小时在线,提升响应效率、降低人力成本、优化客户体验,赋能服务智能化升级。" /> <meta name="keywords" content="AI客服,电商AI智能客服,AI智能客服, 电商客服, AI客服平台,自动回复, 客服外包, MacsMind, 客服系统,智能客服,淘宝AI客服,拼多多AI客服,抖店AI客服,微信AI客服,AI客服机器人,全平台覆盖,聚合平台,AI客服源码,AI客服定制,AI客服开源" /> <title>MacsMind |电商AI智能客服 | 免费试用 | 10000+客户案例</title> <style> #loadingPage { color: rgba(0, 0, 0, 0.45); font-size: 12px; } /* 粒子效果 */ .particle { position: absolute; background: #f0f2f5; border-radius: 50%; animation: float 4s ease-in-out infinite; } .loading-content { height: calc(100vh - 16px); display: flex; align-items: center; flex-direction: column; justify-content: center; } @keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-20px); } } /* 标题样式 */ .loading-text { font-family: 'Orbitron', sans-serif; font-size: 3rem; /* color: #fff; */ text-shadow: 0 0 15px rgba(255, 255, 255, 0.5); text-align: center; animation: pulse 2s infinite; } @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } } /* 进度条样式 */ .progress-bar { width: 80%; height: 10px; background: rgba(255, 255, 255, 0.3); border-radius: 50px; margin: 2rem auto; overflow: hidden; } .progress { height: 100%; background: linear-gradient(90deg, #ff6b6b, #4ecdc4); transition: width 0.5s ease; } </style> <script type="module" crossorigin src="/static/voragowebsite/js/index-DuxpX2AH.js"></script> <link rel="modulepreload" crossorigin href="/static/voragowebsite/js/vendor-Dim6iiIr.js"> <link rel="modulepreload" crossorigin href="/static/voragowebsite/js/lodash-qFkpNywP.js"> <link rel="modulepreload" crossorigin href="/static/voragowebsite/js/ant-boABeEBK.js"> <link rel="stylesheet" crossorigin href="/static/voragowebsite/css/index-ukGitYMe.css"> </head> <body> <div id="loadingPage"> <!-- 粒子容器 --> <div class="particles-container"></div> <!-- 主要内容 --> <div class="loading-content"> <h1 class="loading-text">星际穿越系统启动中...</h1> <div class="progress-bar"> <div class="progress"></div> </div> </div> </div> <div id="app"></div> <script> // 生成粒子效果 const particleContainer = document.querySelector('.particles-container') for (let i = 0; i < 50; i++) { const particle = document.createElement('div') particle.className = 'particle' particle.style.left = `${Math.random() * 100}%` particle.style.animationDuration = `${Math.random() * 2 + 1}s` particle.style.width = `${Math.random() * 2 + 1}px` particle.style.height = `${Math.random() * 2 + 1}px` particle.style.animationDelay = `${Math.random() * 2}s` particle.style.top = `${Math.random() * 100}%` particle.style.transform = `rotate(${Math.random() * 360}deg)` particleContainer.appendChild(particle) } // 动态进度条 const progress = document.querySelector('.progress') let progressValue = 0 const interval = setInterval(() => { progress.style.width = `${progressValue}%` progressValue += 1 if (progressValue >= 100) { clearInterval(interval) // 模拟加载完成跳转 // setTimeout(() => { // window.location.href = 'index.html'; // 替换为目标页面 // }, 1500); } }, 30) </script> </body> </html>这个是我的
最新发布
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值