我可以从外部javascript访问控制台命令行API(如Firebug或Chrome Inspector控制台中的$$和traceAll)吗?
是否可以从外部api访问 简单的例子: HTML我可以从外部javascript访问控制台命令行API(如Firebug或Chrome Inspector控制台中的$$和traceAll)吗?,javascript,api,console,command,firebug,Javascript,Api,Console,Command,Firebug,是否可以从外部api访问 简单的例子: HTML 我不想加载像jQuery或Zepto这样的外部库,因为这样的库已经在本地加载了。回答你的问题,不。但我认为你真的不想加载。API可能会更改,从而破坏您的代码。如果您只需要查询选择器。我认为您最好使用MDN上的代码片段 function $ (selector, el) { if (!el) {el = document;} return el.querySelector(selector); } function $$ (sele
我不想加载像jQuery或Zepto这样的外部库,因为这样的库已经在本地加载了。回答你的问题,不。但我认为你真的不想加载。API可能会更改,从而破坏您的代码。如果您只需要查询选择器。我认为您最好使用MDN上的代码片段
function $ (selector, el) {
if (!el) {el = document;}
return el.querySelector(selector);
}
function $$ (selector, el) {
if (!el) {el = document;}
return el.querySelectorAll(selector);
// Note: the returned object is a NodeList.
// If you'd like to convert it to a Array for convenience, use this instead:
// return Array.prototype.slice.call(el.querySelectorAll(selector));
}
alert($('#myID').id);
如果某人的浏览器中没有命令行,该怎么办?这些命令将失败。我认为它们是分开的,因为如果存在这种功能,那将是一个巨大的安全漏洞,因为输入命令行Api的命令将粘贴到页面中,并使用eval()进行评估。这将允许恶意站点运行脚本注入并访问浏览器的会话信息。
$$('#myDiv').textContent = 'this will not work';
function $ (selector, el) {
if (!el) {el = document;}
return el.querySelector(selector);
}
function $$ (selector, el) {
if (!el) {el = document;}
return el.querySelectorAll(selector);
// Note: the returned object is a NodeList.
// If you'd like to convert it to a Array for convenience, use this instead:
// return Array.prototype.slice.call(el.querySelectorAll(selector));
}
alert($('#myID').id);