如何使用jquery选择所有非提交、重置或按钮的输入?
我试图选择除 input type="submit/reset/button 之外的所有输入元素
我尝试制作这样的选择器:
inputSelector = 'input:not(input[type=button], input[type=submit], input[type=reset]), textarea, select';
但这不起作用,因为提交按钮总是进入最终选择。
知道出了什么问题吗与上述
谢谢!
I'm trying to select all input elements except input type="submit/reset/button
I have tried to make a selector like this:
inputSelector = 'input:not(input[type=button], input[type=submit], input[type=reset]), textarea, select';
But this does not work, because the submit buttons always make into the final selection.
Any idea what's wrong with the above.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将您的选择器修改为链
.not(...)
,如下所示:这使其(可以说)更易于阅读,并且应该按照您的预期工作。
Try modifying your selector to chain
.not(...)
like:This makes it (arguably) easier to read, and should work how you expect.
这个答案可以说比迈克尔·罗宾逊的更难阅读,但我发现它更简洁。您可以使用
:input
来选择它来收集所有表单元素,然后使用:not()not()
函数code> 每个不需要的输入类型的选择器。来自 jQuery 的 API 文档 (https://api.jquery.com/input-selector/ ):
类似“CSS”的选择器版本,
:not()
选择器是独立的,也可以在 CSS 3 中使用:This answer is arguably harder to read than Michael Robinson's, but I find it more succinct. Rather than run the
not()
function, you can select for it using:input
to gather all form elements, then filter with the:not()
selector for each unwanted input type.From jQuery's API documentation (https://api.jquery.com/input-selector/):
The "CSS"-like selector version, the
:not()
selectors are separate, and can be used in CSS 3, too:更短、更简洁的方法:
或者
Even shorter, more concise approach:
Or