I've starting using the Wijmo toolkit, and came across quite a few example selectors similar to this in their documentation pages:

$(":input[type='radio']").wijradio();

I'd have written mine like this:

$('input[type=radio]').wijradio();

这些都是一样的还是我遗漏了什么?

Note that there are two differences above: the first selector is prefixed with a colon and has quotes for the input type.

推荐答案

:input is a jQuery extension while input is a CSS selector.

textareabuttonselect元素将由前者匹配,但后者不匹配.

The latter is faster, so use it for your specific radio example. Use :input when you want "all form elements" even if they aren't strictly <input> tags. Even in that case, the recommendation is to use a standard CSS selector first, then use .filter(':input') on that set.

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").

In the 1.7.2 source, the :input filter tests a regular expression against the nodeName:

input: function( elem ) {
            return (/input|select|textarea|button/i).test( elem.nodeName );
},

Jquery相关问答推荐

如何使用 jQuery 禁用粘贴(Ctrl+V)?

jQuery - 向下滚动时缩小的粘性标题

jQuery: Select 属性大于值的所有元素

如何使用 jQuery 重置 jquery Select 的 Select 选项?

jQuery 中的 $this 与 $(this)

如何计算具有相同类的元素数量?

jQuery/JavaScript 碰撞检测

jquery click 不适用于 ajax 生成的内容

jquery 从特定表单获取所有输入

如何触发href元素的点击事件

使用 MVC、C# 和 jQuery 导出为 CSV

如何将文本从 div 复制到剪贴板

如何清除/重置 jQuery UI Datepicker 日历上的选定日期?

C# String.IsNullOrEmpty Javascript 等效项

所有但不是jQuery Select 器

如何让 twitter bootstrap 子菜单在左侧打开?

如何使用 JQuery 获取 GET 和 POST 变量?

查找 id 以开头的 html 元素

调整浏览器大小时如何自动居中 jQuery UI 对话框?

如何在没有鼠标事件的情况下在 jQuery 中获取鼠标位置?