在 Google Chrome 检查器上加载 jQuery 的命令?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9624972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 11:04:51  来源:igfitidea点击:

Command for loading jQuery on Google Chrome inspector?

jquerygoogle-chromeweb-inspector

提问by Alpha

I remember seeing that there was a specific command you could put on Google Chrome's inspector console for it to load jQuery and allow you to execute jQuery commands.

我记得看到有一个特定的命令可以放在 Google Chrome 的检查器控制台上,以便它加载 jQuery 并允许您执行 jQuery 命令。

However, I cannot remember which command it was, and searching online only brings me unrelated results.

但是,我不记得它是哪个命令,而在线搜索只会给我带来不相关的结果。

Anyone knows which is that command?

有谁知道那个命令是什么?

Thanks!

谢谢!

EDIT:Years later I had realized that I was asking for the $$function in the console. However, this is not jQuery but provides a similar selector option, most likely a shorthand for document.querySelectorAll. The answers here address adding jQuery for real, with all of its functionality.

编辑:多年后我意识到我$$在控制台中要求该功能。然而,这不是 jQuery,而是提供了一个类似的选择器选项,很可能是document.querySelectorAll. 此处的答案解决了真正添加 jQuery 及其所有功能的问题。

回答by Rob W

You mean, a script to load jQuery in an arbitrary page? I have constructed the following cross-browser bookmarklet for this purpose:

您的意思是,在任意页面中加载 jQuery 的脚本?为此,我构建了以下跨浏览器书签:

javascript:if(!window.jQuery||confirm('Overwrite\x20current\x20version?\x20v'+jQuery.fn.jquery))(function(d,s){s=d.createElement('script');s.src='https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.js';(d.head||d.documentElement).appendChild(s)})(document);

It detects whether jQuery exists. If it does, a confirmation dialog appears, in which the current version is shown, so that you can decide whether it's OK to overwtite the existing jQuery object.

它检测 jQuery 是否存在。如果是,则会出现一个确认对话框,其中显示当前版本,以便您可以决定是否可以覆盖现有的 jQuery 对象。

Currently, jQuery 1.8 is loaded from a CDN over SSL.

目前,jQuery 1.8 是通过 SSL 从 CDN 加载的。

To save you time from editing, here's the same bookmarklet as the top of the answer, but getting the latest version(instead of a fixed one) from http://code.jquery.com/:

为了节省您的编辑时间,这里有与答案顶部相同的书签,但从以下位置获取最新版本(而不是固定版本http://code.jquery.com/

javascript:if(!window.jQuery||confirm('Overwrite\x20current\x20version?\x20v'+jQuery.fn.jquery))(function(d,s){s=d.createElement('script');s.src='http://code.jquery.com/jquery.js';(d.head||d.documentElement).appendChild(s)})(document);

Note: Having the latest version is nice, but don't be surprised when jQuery "behaves weird" (=updated).

注意:拥有最新版本很好,但是当 jQuery “表现怪异”(=更新)时不要感到惊讶。

回答by Ravinder Kumar

You can also create a chrome snippet which load jQuery on chrome inspector ( how create custom snippets)

您还可以创建一个在 Chrome 检查器上加载 jQuery 的 chrome 片段(如何创建自定义片段

Snippet code:

片段代码:

(function() {
  if (! window.jQuery ) {
    var s = document.createElement('script');
    s.type = 'text/javascript';
    s.async = true;
    s.src = '//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js'; // you can change this url by latest jQuery version
    (document.getElementsByTagName('head')[0] ||
      document.getElementsByTagName('body')[0]).appendChild(s);
  }
}());