jquery, submit form when field loses focus

后端 未结 3 1922
北海茫月
北海茫月 2021-01-05 16:36

How can I submit a form when a field (In this case the form only has one field) loses focus?

I tried this, but it\'s not working:

$(\"form\").submit(         


        
相关标签:
3条回答
  • 2021-01-05 16:53
    $('form :input').blur(function() {
        $(this).closest('form').submit();
    });
    
    0 讨论(0)
  • 2021-01-05 17:00

    What about this

    var $yourForm = $('#form');
    
    $yourForm.find('input').eq(0).blur(function() {
    
        $yourForm.submit();
    });
    
    0 讨论(0)
  • 2021-01-05 17:17

    Trigger the form's submit() event when the field loses focus. You can detect this by attaching a blur() event handler to it.

    $("#field").blur(function() {
      $("#form").submit();
    });
    

    If you field doesn't have an ID or other means of easily identifying it (which I would recommend) you could also do something like this:

    $("#form :input").blur(function() {
      $("#form").submit();
    });
    

    since there's only one field.

    0 讨论(0)
提交回复
热议问题