首页 > 浏览器中 $() 和 $$() 是不是标准?

浏览器中 $() 和 $$() 是不是标准?



$同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

类似的还有:

Chrome的文档

【热门文章】
【热门文章】