继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

js实现的简单文本框倒计时

ddlowell
关注TA
已关注
手记 2
粉丝 1
获赞 49

<!DOCTYPE html>
<html>
<head>
<title> countdown counter</title>
<meta charset="UTF-8">
<style type="text/css">

box{
        position: absolute;
        width: 350px;
        height: 350px;
        border: 3px solid #aaa;
        border-radius: 20px;
        margin: 100px 400px;
        background-color: #9cf;
    }
    input{
        float: left;
        width: 140px;
        height: 300px;
        margin-top: 25px;
        margin-left: 20px;
        border: 3px solid #aaa;
        border-radius: 20px;
        font-size: 220px;
        text-indent: 10px;
    }
    #btn{
        position: absolute;
        width: 80px;
        height: : 50px;
        font-size: 20px;
        top: 500px;
        left: 550px;
    }
</style>

</head>
<body>
<div id="box">
<form>
<input type="text" id="txt1">
<input type="text" id="txt2">
</form>
</div>
<button id="btn" onclick="func()">开 始</button>
<script type="text/javascript">
function func(){
var txt1v = parseInt(document.getElementById("txt1").value);
var txt2v = parseInt(document.getElementById("txt2").value);
var txt1 = document.getElementById("txt1");
var txt2 = document.getElementById("txt2");
if (txt1v < 0 txt1v > 6 txt2v < 0 txt2v > 9 (txt1v == 6 && txt2v != 0)) {
alert("您的输入有误。");
}else{
var t = setInterval(function update(){
if (txt2v == 0) {
if (txt1v == 0) {
clearInterval(t);
location.href = "http://www.baidu.com";
return;
}
txt1v -= 1;
txt2v = 9;
txt1.value = txt1v;
txt2.value = txt2v;
}else{
txt2v -= 1;
txt2.value = txt2v;
}
}, 1000);
}
}
</script>
</body>
</html>

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP