Powerful jQuery for SubmitOnce
jQuery is pretty powerful. It's pretty easy to write a jquery js without change any html code.
I just wrote a small js to finish one task: disable the "submit" button when submit the form and let Ctrl+Enter submit the form like QQ message.
code is pretty simple:
If we are not using jQuery, we need change every <form in html files.(add onsubmit="javascript:SubmitOnce()" like).
jQuery operate on every form without changing any html files. that's amazing!
enjoy();
I just wrote a small js to finish one task: disable the "submit" button when submit the form and let Ctrl+Enter submit the form like QQ message.
code is pretty simple:
$(document.forms).each( function(theform) {
// disabled the Submit and Reset when submit a form
// to avoid duplicate submit
$(theform).submit( function() {
$('input:submit').attr( { disabled : 'disabled' } );
$('input:reset').attr( { disabled : 'disabled' } );
} );
// Press Ctrl+Enter to submit the form. like QQ.
$(theform).keypress( function(evt) {
var x = evt.keyCode;
var q = evt.ctrlKey;
if (q && ( x == 13 || x == 10)) {
theform.submit();
}
} );
} );If we are not using jQuery, we need change every <form in html files.(add onsubmit="javascript:SubmitOnce()" like).
jQuery operate on every form without changing any html files. that's amazing!
enjoy();
0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home