Resetting a multi-stage form with jQuery

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

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


Trouble i

30条回答
  •  天命终不由人
    2020-11-22 01:31

    Here is something to get you started

    $('form') // match your correct form 
    .find('input[type!=submit], input[type!=reset]') // don't reset submit or reset
    .val(''); // set their value to blank
    

    Of course, if you have checkboxes/radio buttons, you'll need to modify this to include them as well and set .attr({'checked': false});

    edit Paolo's answer is more concise. My answer is more wordy because I did not know about the :input selector, nor did I think about simply removing the checked attribute.

提交回复
热议问题