在JavaScript控制台中包含jQuery [英] Include jQuery in the JavaScript Console

查看:240
本文介绍了在JavaScript控制台中包含jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以在Chrome JavaScript控制台中为不使用它的网站添加jQuery?例如,在网站上我想获取表格中的行数。我知道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;

该网站不使用jQuery。我可以从命令行添加吗?

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

推荐答案


在浏览器的JavaScript控制台中运行,然后jQuery应该可用......

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();

注意:如果网站的脚本与jQuery冲突(其他库)等等。你仍然可能遇到问题。

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

做得更好,创造一个Bookmark让它变得非常方便,让我们这样做,并且一些反馈也很棒:

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


  1. 右键单击书签栏,然后单击添加页面

  2. 根据需要命名,例如注入jQuery,并对URL使用以下行:




javascript :( function(e,s) {e.src = s; e.onload = function(){jQuery.noConflict(); console.log('jQuery inject')}; 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')

以下是格式化的代码:

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

这里使用官方的jQuery CDN URL,可以随意使用自己的CDN /版本。

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

这篇关于在JavaScript控制台中包含jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆