admin管理员组文章数量:1201411
Does Bootstrap offer anything for clearing form input fields via a button?
Or do I need to roll my own through jquery?
From this post jQuery Validate resetForm() doesn't reset the onFocus validation, there seems to be a resetForm() method coming from jquery but I always get a object doesn't support method when I try to access that method.
Does Bootstrap offer anything for clearing form input fields via a button?
Or do I need to roll my own through jquery?
From this post jQuery Validate resetForm() doesn't reset the onFocus validation, there seems to be a resetForm() method coming from jquery but I always get a object doesn't support method when I try to access that method.
Share Improve this question edited May 23, 2017 at 12:26 CommunityBot 11 silver badge asked Jan 7, 2015 at 18:41 4thSpace4thSpace 44.3k101 gold badges306 silver badges493 bronze badges 2 |3 Answers
Reset to default 13You can use reset method (this is DOM element method, it is not jQuery object method), like this
$('form').get(0).reset() // or $('form')[0].reset()
Similar to other answers, if you want to reset the form (not necessarily clear it) you can use the following:
<button type="reset">
It's a little cleaner than embedding jQuery or javascript calls in the onclick...
This worked for me (clearing the fields, not just resetting the form fields to inital value):
$(':input').val('');
but it seems to have side effects like submitting the form.
本文标签: javascriptClearing form input fields in BootstrapStack Overflow
版权声明:本文标题:javascript - Clearing form input fields in Bootstrap? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738573098a2100717.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$('form').get(0).reset()
– Oleksandr T. Commented Jan 7, 2015 at 18:42resetForm()
is only part of the jQuery Validate plugin, not a jQuery method. – Sparky Commented Jan 8, 2015 at 16:40