用于选择所有类型文本框的 jQuery 选择器

标签 jquery

有没有一种简单的方法来选择所有类型的文本框?

即。 <input type=文本或电子邮件或网址或号码 />

我不介意密码或文本区域。

例如。我有这段代码,它选择具有自定义属性(“特殊”)的所有文本输入,可以缩短吗?

$("input[type='text'][special],input[type='email'][special],input[type='url'][special],input[type='password'][special]")

最佳答案

:input selector 是吗?涵盖您感兴趣的案例?

$(":input[special]")

文档:

The :input selector basically selects all form controls.

Additional Notes:
Because :input is a jQuery extension and not part of the CSS specification, queries using :input cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. To achieve the best performance when using :input to select elements, first select the elements using a pure CSS selector, then use .filter(":input").

$("[special]").filter(":input"); 

关于用于选择所有类型文本框的 jQuery 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13149248/

相关文章:

javascript - Javascript 中的表单填写不起作用?

javascript - jQuery:使用 select() 而不是 change() 选择 <option> 内容

javascript - 如何在php中将值从数据库传递到弹出窗口?

jquery - 在 Angular 指令中以 noconflict 运行 jQuery 插件 diff2html

javascript - 如何将元素附加到动态生成的元素

javascript - 如果我想定位桌面和移动设备,是否应该使用 "onmousedown"事件?

javascript - jQuery slider 自动播放按钮不起作用

javascript - 如何清除 Selectize.js 下拉列表中的选定值?

javascript - 通过 jQuery 访问被单击的元素内的 <li> 的最简单方法是什么?

javascript - Jquery 多选事件处理程序