开发者

Reset a form with jquery using specific selector

开发者 https://www.devze.com 2023-02-07 07:28 出处:网络
I have a form like this: <form id=\'formi开发者_如何学Cd\'> <input type=\'text\' name=\'textname\'>

I have a form like this:

<form id='formi开发者_如何学Cd'>

<input type='text' name='textname'>
<input type='button' id='resetbutton'>

</form>

Now I want to jquery code which submit a form with id=formid when a button(id='resetbutton' in id=formid form) is clicked. And I want it to also run in IE7.

Thanks for your help.


You should use the native reset button:

<input type="reset" value=" Reset ">

and extend it with jquery:

$('#formid').children('input[type="reset"]').click(function() {
//do what you want
};


$("#resetbutton").click(function(){
   $("#formid").submit()
});    

this will set the click event on the button and submit the form when it's executed.


(function () {
    var $formObject = $("#formid").eq(0);

    $("#resetbutton", $formObject.get(0)).click(function (){
          $formObject.submit();
    });
})();
0

精彩评论

暂无评论...
验证码 换一张
取 消