If a button can be clicked multiple times in a short time, it may be maliciously clicked by the user. To prevent this, it can be set to only click once within a certain period of time, and clicking buttons is prohibited at other times.
The code is as follows:
The code copy is as follows:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Js timed event</title>
<script src="js/jquery-1.9.1.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" value="click me" id="btn" onclick="show()" />
</div>
<script type="text/javascript">
/*
timeId=window.setTimeout("method()",1000); window.clearTimeout(timeId); timed execution
timeId=window.setInterval("method()",1000); window.clearInterval(timeId); loop execution
*/
var nn = 30;
var tipId;
function show() {
tipId = window.setInterval("start()", 1000); //Call the start() method every 1 second
}
function start() {
if (nn > 0) {
var vv = "Click me (" + nn + ")";
$("#btn").attr("disabled", "disabled"); //Make the button not clicked
$("#btn").attr("value", vv); //Change the text on the button
nn--;
} else {
nn = 30;
$("#btn").removeAttr("disabled"); // enable button to be clicked
$("#btn").attr("value", "click me"); //Change the text on the button
window.clearInterval(tipId); //Clear loop event
}
}
</script>
</form>
</body>
</html>