我想在网页中插入倒计时的功能
发布网友
发布时间:2022-04-30 08:12
我来回答
共3个回答
热心网友
时间:2022-06-19 14:48
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>test1</title>
<script type="text/javascript">
function oval() {
var times = document.getElementById("times");
if (this.indexs == 0) {
clearTimeout(this.timer);
this.timer = null;
} else {
times.innerHTML = (!!this.indexs ? --this.indexs : this.indexs = 100) + "秒";
this.timer = setTimeout(oval, 1000);
}
}
</script>
</head>
<body>
<div id="times"></div>
<input type="button" value="start" onclick="oval();this.disabled=true" id="s"/>
<input type="button" value="reset" onclick="clearTimeout(window.timer); window.timer = null; document.getElementById('times').innerHTML='100秒'; window.indexs = 101;document.getElementById('s').disabled = false;" />
</body>
</html>
那个onclick="window.indexs = 101是设置成100秒的意思
热心网友
时间:2022-06-19 14:48
<html>
<head><title>test1</title>
</head>
<body>
<div id="times"></div>
<input type="button" value="reset" onclick="window.indexs = 101;" />
<script type="text/javascript">
var times = document.getElementById("times");
void (function oval() {
if (this.indexs == 0) {
clearTimeout(this.timer);
this.timer = null;
} else {
times.innerHTML = (!!this.indexs ? --this.indexs : this.indexs = 100) + "秒";
this.timer = setTimeout(oval, 1000);
}
})();
</script>
</body>
</html>
热心网友
时间:2022-06-19 14:49
<!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 runat="server">
<title></title>
<script type="text/javascript">
function start()
{
document.getElementById("time").innerHTML=document.getElementById("settime").value
changeTime()
}
function end()
{
document.getElementById("time").innerHTML=0
changeTime()
}
function changeTime() {
var time = parseInt(document.getElementById("time").innerHTML)
time--
if (time <= 0) {
}else {
document.getElementById("time").innerHTML = time
setTimeout(changeTime,1000)
}
}
</script>
</head>
<body>
<form id="form1" >
<div>
<p>
<input id="settime" type="text" value="5" />
<br />
<span id="time"></span>秒钟 </p>
<p>
<span id="btn1" onclick="start()">点我开始</span>
<span id="btn2" onclick="end()">点我结束</span>
</p>
</div>
</form>
</body>
</html>