Skip to content

Instantly share code, notes, and snippets.

@java-MagicWang
Created July 9, 2014 05:46
Show Gist options
  • Save java-MagicWang/87413336c61c4b23ef36 to your computer and use it in GitHub Desktop.
Save java-MagicWang/87413336c61c4b23ef36 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<div>
<span id="timer"></span>
<br/>
<div>
<input id="send" type="button" value="send" onclick="javascript:sendEmail();"/>
<input type="button" value="cancel" onclick="javascript:cancel();"/>
</div>
</div>
</body>
</html>
var count=4;
var counter;//1000 will run it every 1 second
function sendEmail() {
counter = setInterval(timer, 1000);
$("#send").attr("disabled","disabled");
}
function cancel() {
clearInterval(counter);
$("#timer").html("Email has bean canceled!");
$("#send").removeAttr("disabled");
count=4;
}
function timer() {
count=count-1;
if (count <= 0) {
clearInterval(counter);
//counter ended, do something here
count=4
$("#timer").hide();
$("#send").removeAttr("disabled");
return;
}else {
$("#timer").show();
$("#timer").html("sending... "+count+" secs");
}
//Do code for showing the number of seconds here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment