问题
So I am trying to submit the form through jQuery onblur (i.e. As soon as the focus leaves the password field, form submits through jQuery). There are similar questions but it's not what I am looking for. I tried using the document.getElementById but it isn't working.
Any help is appreciated. Thanks in advance.
<script>
$(function(){
$("#pswd").blur({
$("#myForm").submit();
});
});
</script>
回答1:
As @dvenkatsagar suggested, you have some syntax errors,
Live Preview: http://codepen.io/larryjoelane/pen/VedXqr
(function($){
//I selected the body tag first because I do not know if you are creating
//the pswd element dynamically
$("body").on("blur","#pswd",function(e){
$("#myForm").submit();
});
})(jQuery);
It is not necessary but I changed the way your closure was structured just in case you want to use other libraries in the future inside your closure besides jQuery.
回答2:
Well the only problem I can see the function blur() and the way it is written, I think you should change it like this:
$(function(){
$("#pswd").on("blur",function(){
$("#myForm").submit();
});
})();
来源:https://stackoverflow.com/questions/35109582/how-to-submit-form-through-jquery-onblur