Count the number of times a submit button has been clicked
Is there a way I can tell how many times a form submit button has been cli开发者_Python百科cked using jQuery? If so, can someone please provide a code sample? Thanks!
Easy.
html:
<form id="form">
<input type="button" id="Submit" name="Submit" value="Submit" />
</form>
javascript:
var count = 0;
$(document).ready(function(){
$("form#Submit").submit(function(){
count++;
});
});
If you are posting the form to the server, you may find it easier, and more reliable, to track the form submissions from the server-side.
You can increment a variable in the click or submit events.
精彩评论