Resetting a multi-stage form with jQuery

前端 未结 30 2386
谎友^
谎友^ 2020-11-22 00:58

I have a form with a standard reset button coded thusly:


Trouble i

30条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 01:32

    I'm using Paolo Bergantino solution which is great but with few tweaks... Specifically to work with the form name instead an id.

    For example:

    function jqResetForm(form){
       $(':input','form[name='+form+']')
       .not(':button, :submit, :reset, :hidden')
       .val('')
       .removeAttr('checked')
       .removeAttr('selected');
    }
    

    Now when I want to use it a could do

    Reset
    

    As you see, this work with any form, and because I'm using a css style to create the button the page will not refresh when clicked. Once again thanks Paolo for your input. The only problem is if I have defaults values in the form.

提交回复
热议问题