jquery清除表单中所有元素的值

来源:互联网 发布:windows隐私声明 编辑:程序博客网 时间:2024/05/22 07:48
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.


很强大,包括了所有的情况

原创粉丝点击