纯用jquery实现,按钮倒数5秒后才能点击
展开全部
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>按钮倒数5秒后才能点击</title>
</head>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<body>
<button type="button" id="test" disabled>点击</button>
</body>
<script type="text/javascript">
setTimeout(function(){
$("button[id='test']").removeAttr("disabled");
},5000)
</script>
</html>
追问
可以在按钮上显示倒数5秒的效果吗?
追答
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>按钮倒数5秒后才能点击</title>
</head>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<body>
<button type="button" id="test" disabled>点击(5)</button>
</body>
<script type="text/javascript">
var i=5;
var timehwnd=setInterval("Countdown()",1000);
function Countdown(){
i--;
if(i == 0){
$("button[id='test']").html("点击");
$("button[id='test']").removeAttr("disabled");
clearInterval(timehwnd);
}else{
$("button[id='test']").html("点击("+i+")");
}
}
</script>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询