<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.con {
width: 200px;
height: 200px;
background: red;
}
.tou {
width: 200px;
height: 30px;
line-height: 30px;
background: #a7cbff;
}
.tou button {
float: left;
}
.tou .ret {
float: right;
}
</style>
<script type="text/javascript">
// 定义vote函数,计算票数
// 定义disabled函数,禁用投票按钮
function vote(btn){
// var num = parseInt(btn.parentNode.getElementById("total")[0].innerText);
var numNode = document.getElementById("total");
var num = parseInt(numNode.innerText)+1;
numNode.innerText= num;
btn.disabled =true;
debugger;
setTimeout(a,3000);
}
function a(){
document.getElementsByTagName("button")[0].disabled =false;
// alert("Hello")
// btn.disabled=false
}
</script>
</head>
<body>
<div class="con">投票内容</div>
<div class="tou">
<button onclick="vote(this)">投票</button>
<span class="ret">总票数:<span id="total">0</span></span>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.con {
width: 200px;
height: 200px;
background: red;
}
.tou {
width: 200px;
height: 30px;
line-height: 30px;
background: #a7cbff;
}
.tou button {
float: left;
}
.tou .ret {
float: right;
}
</style>
<script type="text/javascript">
// 定义vote函数,计算票数
// 定义disabled函数,禁用投票按钮
function vote(btn){
// var num = parseInt(btn.parentNode.getElementById("total")[0].innerText);
var numNode = document.getElementById("total");
var num = parseInt(numNode.innerText)+1;
numNode.innerText= num;
btn.disabled =true;
debugger;
setTimeout(a,3000);
}
function a(){
document.getElementsByTagName("button")[0].disabled =false;
// alert("Hello")
// btn.disabled=false
}
</script>
</head>
<body>
<div class="con">投票内容</div>
<div class="tou">
<button onclick="vote(this)">投票</button>
<span class="ret">总票数:<span id="total">0</span></span>
</div>
</body>
</html>