How to reset a form using jQuery with .reset() method

前端 未结 16 1313
清酒与你
清酒与你 2020-11-22 17:28

I had working code that could reset my form when I click on a reset button. However after my code is getting longer, I realize that it doesn\'t work anymore.



        
16条回答
  •  长发绾君心
    2020-11-22 17:42

    http://jsfiddle.net/8zLLn/

      $('#configreset').click(function(){
            $('#configform')[0].reset();
      });
    

    Put it in JS fiddle. Worked as intended.

    So, none of the aforementioned issues are at fault here. Maybe you're having a conflicting ID issue? Is the click actually executing?

    Edit: (because I'm a sad sack without proper commenting ability) It's not an issue directly with your code. It works fine when you take it out of the context of the page that you're currently using, so, instead of it being something with the particular jQuery/javascript & attributed form data, it has to be something else. I'd start bisecting the code around it out and try to find where it's going on. I mean, just to 'make sure', i suppose you could...

    console.log($('#configform')[0]);
    

    in the click function and make sure it's targeting the right form...

    and if it is, it has to be something that's not listed here.

    edit part 2: One thing you could try (if it's not targeting it correctly) is use "input:reset" instead of what you are using... also, i'd suggest because it's not the target that's incorrectly working to find out what the actual click is targeting. Just open up firebug/developer tools, whathave you, toss in

    console.log($('#configreset'))
    

    and see what pops up. and then we can go from there.

提交回复
热议问题