1.$(':input','#myform')
2. .not(':button, :submit, :reset, :hidden')
3. .val('')
4. .removeAttr('checked')
5. .removeAttr('selected');
清楚表单内所有元素的值,包含了所有的情况。
It is using the :input
selector which will match all input, textarea, select and button elements. Since we are passing #myform
as the second argument, it will only find inputs inside this form
element. Then it filters out all buttons, submits, resets and hidden
inputs using not()
. Then it is using val()
to set the value of the remaining fields to an empty string, and then it uses removeAttr
to remove the checked
and selected
attribute of the fields in case you have any radio/checkbox/select inputs. Tada.
很强大,包括了所有的情况
本文介绍了一种使用jQuery选择器和方法来清除HTML表单中所有输入元素值的方法,包括但不限于文本框、下拉列表、复选框和单选按钮等。
1236

被折叠的 条评论
为什么被折叠?



