喵-见缝插针 2011-09-19 16:42 采纳率: 0%
浏览 337
已采纳

在 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条回答 默认 最新

  • 谁还没个明天 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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!