$同document.querySelector
,$$同document.querySelectorAll
应该不是标配,但是比较新的浏览器似乎都支持
仅仅是为了方便调试使用,并不是所有浏览器都有。Chrome
中是支持的,ff
中返回的是这样
$$
function JSTH_$$()
$
function JSTH_$()
w8.1 edge,IE10,IE9
默认版本返回的是这样
$
>function(selectors,startNode){...
>$$
>function(selectors,startNode){...
而IE8
中返回的是下面这样,因此在IE8
下需要使用$()
和$$()
>$$
>function(selectors, startNode) {
if (startNode) {
return startNode.querySelectorAll.call(startNode, selectors);
}
return window.document.querySelectorAll.apply(window.document, arguments);
}
> $
> function(selectors, startNode) {
if (startNode) {
return startNode.querySelector.call(startNode, selectors);
}
return window.document.querySelector.apply(window.document, arguments);
}
浏览器自带,实际上运行的都是:
with(__commandLineAPI) {
xxx
}
这是部分浏览器让开发者在控制台更加方便调试所设。
$
表示document.querySelector
$$
表示document.querySelectorAll
类似的还有:
-
$x
表示返回指定xpath的元素 -
$_
返回上次表达式的结果 -
$0
-$4
返回上五次选取的DOM节点
Chrome的文档