[英]Can I access the console Command line API (like $$ and traceAll from Firebug or Chrome Inspector Console) from an external javascript?
Is it possible to access the Command Line Api from an external api? 是否可以从外部api访问命令行Api ?
Simple Example: 简单的例子:
HTML HTML
<div id="myDiv"></div>
<script src="myScript.js"></script>
myScript.js myScript.js
$$('#myDiv').textContent = 'this will not work';
I do not wan't to load an external library like jQuery or Zepto because seens like this is already loaded locally. 我不想加载像jQuery或Zepto这样的外部库,因为这样的视图已经在本地加载了。
To answer your question, no. 要回答您的问题,不。 But I don't think you really want to. 但是我不认为你真的想要。 The API may change, breaking your code. API可能会更改,从而破坏您的代码。 If all you're looking for is the query selector. 如果您只需要查询选择器。 I think you are better off using a snippet found on the MDN. 我认为您最好使用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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.