submit form when elements change

后端 未结 4 2000
渐次进展
渐次进展 2021-01-12 03:57

In jQuery, if I assign class=auto_submit_form to a form, it will be submitted whenever any element is changed, with the following code:

/* autom         


        
4条回答
  •  不知归路
    2021-01-12 04:47

    I came up with a generic approach to this:

    $('.autoSubmit, .autoSubmit select, .autoSubmit input, .autoSubmit textarea').change(function () {
        const el = $(this);
        let form;
    
        if (el.is('form')) { form = el; }
        else { form = el.closest('form'); }
    
        form.submit();
    });
    

    All elements of a form:

    Only individual elements

提交回复
热议问题