csdnceshi62 2011-09-19 16:42 采纳率: 100%
浏览 463
已采纳

在 JavaScript 控制台中包含 jQuery

Is there an easy way to include jQuery in the Chrome JavaScript console for sites that do not use it? For example, on a website I would like to get the number of rows in a table. I know this is really easy with jQuery.

$('element').length;

The site does not use jQuery. Can I add it in from the command line?

转载于:https://stackoverflow.com/questions/7474354/include-jquery-in-the-javascript-console

  • 写回答

18条回答

  • perhaps? 2011-09-19 16:44
    关注

    Run this in your browser's JavaScript console, then jQuery should be available...

    var jq = document.createElement('script');
    jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/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();
    

    NOTE: if the site has scripts that conflict with jQuery (other libs, etc.) you could still run into problems.

    Update:

    Making the best better, creating a Bookmark makes it really convenient, let's do it, and a little feedback is great too:

    1. Right click the Bookmarks Bar, and click Add Page
    2. Name it as you like, e.g. Inject jQuery, and use the following line for 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')

    Below is the formatted code:

    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')
    

    Here the official jQuery CDN URL is used, feel free to use your own CDN/version.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(17条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?