开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜