今天发现了一个奇怪的问题,即在 Chrome 的 Console 中使用 $('*')
只能找到一个元素。在网上搜了半天也没找到相应的解释,后来发现是因为对应的网站并没有引用
JQuery,Console 中的$
似乎是 Chrome 提供的。在引用了 JQuery 后问题就解决了。可以在 Console 中输入 $
查看这个 $
到底是不是 JQuery 提供的。
Chrome 提供的 $
>$
<ƒ $(selector, [startNode]) { [Command Line API] }
JQuery 提供的 $
>$
<ƒ ( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
// Need init if jQuery is called (just allow error to be thrown if not included)
return new jQuery…
如果想在 Console 中引用 JQuery,可以输入代码(来源:https://blog.csdn.net/aigoChina/article/details/78864647
)
var importJs=document.createElement('script') //在页面新建一个script标签
importJs.setAttribute("type","text/javascript") //给script标签增加type属性
importJs.setAttribute("src", 'https://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js') //给script标签增加src属性, url地址为cdn公共库里的
document.getElementsByTagName("head")[0].appendChild(importJs) //把importJs标签添加在页面
网友评论