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

2013 年 5 月 4 日
 Part
虽然console支持dollar选择符,but貌似不是jquery的dollar,执行jquery function无果,想在console下载入jquery,求方法。thanks!
13494 次点击
所在节点    程序员
20 条回复
jasya
2013 年 5 月 4 日
是这样嘛...如果页面上加载了jq
再console下就能直接适用jq的
Part
2013 年 5 月 4 日
@jasya 嗯,目前就是想在没有载入jq的页面载入jq。
gDD
2013 年 5 月 4 日
建一个script标签挂到页面上。

类似V2EX页面源代码最后的GA代码,把src换成jQquery地址就行了。
jasya
2013 年 5 月 4 日
或者你写个loadscript的function 需要的时候复制进去
Part
2013 年 5 月 4 日
@gDD 此法not use,看来只能试试load了 @jasya
ljbha007
2013 年 5 月 4 日
很简单 写个chrome扩展 然后注入content script
http://developer.chrome.com/extensions/content_scripts.html
caomu
2013 年 5 月 4 日
我是用这个 http://marklets.com/jQuerify.aspx ,需要的时候点一下。
Part
2013 年 5 月 4 日
用 js load 处理了。@ljbha007 等有空写个扩展试试。
ljbha007
2013 年 5 月 4 日
@Part
把你那个js load代码复制粘贴到一个contentscript.js里边

然后照着这个写个配置文件就可以了
http://developer.chrome.com/extensions/getstarted.html
zythum
2013 年 5 月 4 日
加句这个就可以了
;(function(d, s){d.body.appendChild(s = d.createElement('script')).src = 'http://code.jquery.com/jquery-1.9.1.min.js'})(document,null);

就一行哦。
看看谁还能再简化一下的
zythum
2013 年 5 月 4 日
后面的null没有必要,再把空格去掉

;(function(d,s){d.body.appendChild(s=d.createElement('script')).src='http://code.jquery.com/jquery-1.9.1.min.js'})(document);
jason52
2013 年 5 月 4 日
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
2013 年 5 月 4 日
@zythum
;(function(d,s){d.body.appendChild(s=d.createElement('script')).src='//code.jquery.com/jquery-1.9.1.min.js'})(document);
“http”去掉。
duhastmich
2013 年 5 月 4 日
@zythum 为什么要包到函数里还要弄个s出来。。

顺便提一下,firefox的firebug的firequery 提供一个jquerify 的按钮
zythum
2013 年 5 月 4 日
@duhastmich 因为var s 和上面写个,s 字符要少一些。并且也是局部变量。
作为一句话脚本。应该是越短越好。
朱一是这样像的。


@X_Del 去掉http那就是和主域的协议一样,如果是https,jquery官方木有提供https的地址啊
zythum
2013 年 5 月 4 日
@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
2013 年 5 月 4 日
我js不是非常熟,但是
document.body.appendChild(document.createElement('script')).src='http://code.jquery.com/jquery-1.9.1.min.js';
应该是没有污染的,所以觉得没有必要包。。
zythum
2013 年 5 月 4 日
@duhastmich 这样应该没问题。我发现我s赋值了其实并没有用。
wontoncc
2013 年 5 月 5 日
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
2021 年 8 月 19 日
用油猴脚本加一个引用 jQuery 的语句,设定为在所有网站运行。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://study.congcong.us/t/67682

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX