对于不使用它的网站,是否有一种简单的方法可以在 Chrome JavaScript 控制台中包含 jQuery?例如,在一个网站上,我想获取表格中的行数。我知道使用 jQuery 真的很容易。
$('element').length;
该网站不使用 jQuery。我可以从命令行添加它吗?
最佳答案
在浏览器的 JavaScript 控制台中运行它,然后 jQuery 应该可用...
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type (or see below for non wait option)
jQuery.noConflict();
注意:如果网站的脚本与 jQuery(其他库等)冲突,您仍然可能会遇到问题。
更新:
把最好的做得更好,创建一个书签真的很方便,让我们去做吧,一点点反馈也很棒:
- 右键单击书签栏,然后单击添加页面
- 随意命名,例如注入(inject) jQuery,并使用以下行作为 URL:
javascript:(function(e,s){e.src=s;e.onload=function(){jQuery.noConflict();console.log('jQuery injected')};document.head.appendChild(e);})(document.createElement('script'),'//code.jquery.com/jquery-latest.min.js')
下面是格式化代码:
javascript: (function(e, s) {
e.src = s;
e.onload = function() {
jQuery.noConflict();
console.log('jQuery injected');
};
document.head.appendChild(e);
})(document.createElement('script'), '//code.jquery.com/jquery-latest.min.js')
这里使用的是官方的 jQuery CDN URL,请随意使用自己的 CDN/版本。
关于javascript - 在 JavaScript 控制台中包含 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7474354/