V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Part
V2EX  ›  程序员

如何让chrome开发工具console支持jquery?

  •  
  •   Part · 2013-05-04 14:13:14 +08:00 · 12790 次点击
    这是一个创建于 4012 天前的主题,其中的信息可能已经有所发展或是发生改变。
    虽然console支持dollar选择符,but貌似不是jquery的dollar,执行jquery function无果,想在console下载入jquery,求方法。thanks!
    20 条回复    2021-08-19 13:37:02 +08:00
    jasya
        1
    jasya  
       2013-05-04 14:23:14 +08:00
    是这样嘛...如果页面上加载了jq
    再console下就能直接适用jq的
    Part
        2
    Part  
    OP
       2013-05-04 14:25:23 +08:00
    @jasya 嗯,目前就是想在没有载入jq的页面载入jq。
    gDD
        3
    gDD  
       2013-05-04 14:28:58 +08:00
    建一个script标签挂到页面上。

    类似V2EX页面源代码最后的GA代码,把src换成jQquery地址就行了。
    jasya
        4
    jasya  
       2013-05-04 14:32:49 +08:00
    或者你写个loadscript的function 需要的时候复制进去
    Part
        5
    Part  
    OP
       2013-05-04 14:37:50 +08:00
    @gDD 此法not use,看来只能试试load了 @jasya
    ljbha007
        6
    ljbha007  
       2013-05-04 15:03:37 +08:00
    很简单 写个chrome扩展 然后注入content script
    http://developer.chrome.com/extensions/content_scripts.html
    caomu
        7
    caomu  
       2013-05-04 15:18:11 +08:00
    我是用这个 http://marklets.com/jQuerify.aspx ,需要的时候点一下。
    Part
        8
    Part  
    OP
       2013-05-04 15:20:17 +08:00
    用 js load 处理了。@ljbha007 等有空写个扩展试试。
    ljbha007
        9
    ljbha007  
       2013-05-04 15:23:08 +08:00   ❤️ 1
    @Part
    把你那个js load代码复制粘贴到一个contentscript.js里边

    然后照着这个写个配置文件就可以了
    http://developer.chrome.com/extensions/getstarted.html
    zythum
        10
    zythum  
       2013-05-04 15:30:02 +08:00   ❤️ 2
    加句这个就可以了
    ;(function(d, s){d.body.appendChild(s = d.createElement('script')).src = 'http://code.jquery.com/jquery-1.9.1.min.js'})(document,null);

    就一行哦。
    看看谁还能再简化一下的
    zythum
        11
    zythum  
       2013-05-04 15:31:48 +08:00
    后面的null没有必要,再把空格去掉

    ;(function(d,s){d.body.appendChild(s=d.createElement('script')).src='http://code.jquery.com/jquery-1.9.1.min.js'})(document);
    jason52
        12
    jason52  
       2013-05-04 16:51:08 +08:00   ❤️ 1
    1、打开Chrome浏览器,输入网址:http://forum.csdn.net/SList/HTMLCSS/

    2、按下“Ctrl+Shift+J”打开“Javascript控制台”工具

    3、动态引用jQuery.js文件


    var fileref=document.createElement('script')
    fileref.setAttribute("type","text/javascript")
    fileref.setAttribute("src", 'http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js')
    document.getElementsByTagName("head")[0].appendChild(fileref)
    X_Del
        13
    X_Del  
       2013-05-04 16:51:10 +08:00 via Android   ❤️ 1
    @zythum
    ;(function(d,s){d.body.appendChild(s=d.createElement('script')).src='//code.jquery.com/jquery-1.9.1.min.js'})(document);
    “http”去掉。
    duhastmich
        14
    duhastmich  
       2013-05-04 18:11:21 +08:00
    @zythum 为什么要包到函数里还要弄个s出来。。

    顺便提一下,firefox的firebug的firequery 提供一个jquerify 的按钮
    zythum
        15
    zythum  
       2013-05-04 19:59:17 +08:00
    @duhastmich 因为var s 和上面写个,s 字符要少一些。并且也是局部变量。
    作为一句话脚本。应该是越短越好。
    朱一是这样像的。


    @X_Del 去掉http那就是和主域的协议一样,如果是https,jquery官方木有提供https的地址啊
    zythum
        16
    zythum  
       2013-05-04 20:01:26 +08:00
    @duhastmich

    再说清楚一些。包个闭包是因为防止污染环境。
    为啥要多写个s是因为

    ;(function(d,s){d.body.appendChild(s=d.createElement('script')).src='//code.jquery.com/jquery-1.9.1.min.js'})(document);

    如果不这样写
    ;(function(d){var s;d.body.appendChild(s=d.createElement('script')).src='//code.jquery.com/jquery-1.9.1.min.js'})(document);
    duhastmich
        17
    duhastmich  
       2013-05-04 22:37:54 +08:00
    我js不是非常熟,但是
    document.body.appendChild(document.createElement('script')).src='http://code.jquery.com/jquery-1.9.1.min.js';
    应该是没有污染的,所以觉得没有必要包。。
    zythum
        18
    zythum  
       2013-05-04 22:52:49 +08:00
    @duhastmich 这样应该没问题。我发现我s赋值了其实并没有用。
    wontoncc
        19
    wontoncc  
       2013-05-05 11:04:45 +08:00
    Chrome: Inspect element -> 'Source' on the toolbar -> Expand the sidebar -> 'Sinppets' -> New -> write you own loading script for jQuery -> Execute it with the triangle button on the bottom -> Pull up the console and test it out.

    Once the snippet is written, you can execute it whenever you want.
    kasusa
        20
    kasusa  
       2021-08-19 13:37:02 +08:00
    用油猴脚本加一个引用 jQuery 的语句,设定为在所有网站运行。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5845 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 06:16 · PVG 14:16 · LAX 23:16 · JFK 02:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.