一个实现了在按钮上显示倒计时,倒计时完毕自动将按钮设置为不可用的效果,具体代码如下:
<html> <head> <title>test count down button</title> <script src="http://www.maopiaopiao.com/js/jquery.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $('#btn').click(function () { var count = 3; var countdown = setInterval(CountDown, 1000); function CountDown() { $("#btn").attr("disabled", true); $("#btn").val("Please wait " + count + " seconds!"); if (count == 0) { $("#btn").val("Submit").removeAttr("disabled"); clearInterval(countdown); } count--; } }) }); </script> </head> <body> <input type="button" id="btn" value="Submit" /> </body> </html>