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

Button countdown effect implemented by JQuery_jquery

WBOY
Release: 2016-05-16 15:23:54
Original
1053 people have browsed it

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>

Copy after login

The screenshot of the running effect is as follows:

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template