jQuery 选择器问题(如何选择表单上的所有输入字段,除了按钮和复选框)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3129151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery selector question (how to select all input fields on a form EXCEPT buttons and checkbox)
提问by morpheous
I am trying to select all input fields on a form (except buttons and checkboxes).
我正在尝试选择表单上的所有输入字段(按钮和复选框除外)。
I have got as far as to select all the form input elements on a form with id "myform", but I dont know how to exclude buttons and checkbox items. Does anyone know how to do this?
我已经选择了 ID 为“myform”的表单上的所有表单输入元素,但我不知道如何排除按钮和复选框项目。有谁知道如何做到这一点?
this is what I have so far:
这是我到目前为止:
$("#myform :input")
How do I "filter out" buttons and checkboxes on the form?
如何“过滤掉”表单上的按钮和复选框?
回答by
$("#myform :input:not(:checkbox):not(:button)");
回答by FelipeAls
You can use :not()combined to :checkboxand :buttonselectors:
您可以使用:not()组合到:checkbox和:button选择器:
$("#myform :input:not(:button):not(:checkbox)");
and test it with success with the exampleprovided in the documentation of :input
并使用:input 文档中提供的示例对其进行成功测试
EDIT: :input
also selects textarea
, select
, button
and input[type="hidden"]
according to documentation(and a useful example)
编辑::input
也选择textarea
, select
,button
和input[type="hidden"]
根据文档(和一个有用的例子)