Home  >  Article  >  Web Front-end  >  Button countdown effect implemented by JQuery_jquery

Button countdown effect implemented by JQuery_jquery

WBOY
WBOYOriginal
2016-05-16 15:23:541011browse

The example in this article describes the button countdown effect implemented by JQuery. Share it with everyone for your reference, the details are as follows:

An effect that displays a countdown on the button and automatically sets the button to unavailable when the countdown is completed. The specific code is as follows:

<html>
<head>
<title>test count down button</title>
<script src="jquery1.8.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#btn').click(function () {
var count = 10;
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>

The screenshot of the running effect is as follows:

I hope this article will be helpful to everyone in jQuery programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn