$并$$可以在$返回了选择器的第一个元素的Google Chrome,Firefox和Safari浏览器的任何网页(如果还不包括jQuery)上运行。
这里,
$是 document.querySelector
现价为 document.querySelectorAll
它们是Google Chrome和Firefox浏览器的本机功能,您也可以在Safari中查看$和$$定义。
在任何Google Chrome,Firefox或Safari中打开Google,然后打开“开发人员工具”以检查这些结果...(为什么选择Google,因为它们不会使用jQuery或Moo工具)
$('div'); // returns first DIV in DOM
$$('div'); // returns all DIVs in DOM
Run Code Online (Sandbox Code Playgroud)
在jQuery文档中没有$$声明.jQuery有一个带$字符的默认选择器.也许这个脚本使用另一个javascript库并且与jQuery有一些冲突.在这种情况下,您可以使用jquery.NoConflict以避免此类问题,并设置另一个jquery选择器.
就像是:
var s = jQuery.noConflict();
// something with new jQuery selector
s("div p").hide();
// something with another library's using $()
$("content").style.display = 'none';
Run Code Online (Sandbox Code Playgroud)
如果你的代码有一些喜欢避免冲突的东西:var $$ = jquery.noConfict();你可以使用$$作为jquery选择器:$$("#element").method();
有关文档的更多信息,请访问:http: //api.jquery.com/jQuery.noConflict/
| 归档时间: |
|
| 查看次数: |
6606 次 |
| 最近记录: |