【发布时间】:2014-02-13 19:00:15
【问题描述】:
我正在尝试开发一个简单的 cheome 扩展,但我无法设置 jQuery 来使用它:
这是我的文件结构:
--root
-- manifest.json
-- popup.html
-- 脚本.js
-- js
-- jQuery.js
-- 剪辑.js
这是我在manifest.json 中的代码
{
"manifest_version": 2,
"name": "My ext",
"description": "This is a Development.",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"https://secure.flickr.com/"
],
"content_scripts": [
{
"all_frames": false,
"matches": ["<all_urls>"],
"exclude_matches": [],
"css": [
"css/content/page.css"
],
"js": [
"js/jquery.js",
"js/clip.js"
]
}
]
}
和 popup.html 为:
<!doctype html>
<html>
<head>
<title>My app</title>
<style>body {min-width: 357px;overflow-x: hidden;} </style>
<!--
- JavaScript and HTML must be in separate files: see our Content Security
- Policy documentation[1] for details and explanation.
-
- [1]: http://developer.chrome.com/extensions/contentSecurityPolicy.html
-->
<script src="script.js"></script>
</head>
<body>
<table style="width:300px">
<tr>
<td id="fname">Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
</body>
</html>
最后 script.js 为:
$( "#fname" ).on( "click", function() {
alert( "HI");
});
我还尝试通过从 cdn 调用 jQuery 并在页面上声明文档就绪 JavaScript 来通过 <head> 运行 jQuery,但它也不起作用。
<!doctype html>
<html>
<head>
<title>My app</title>
<style>body {min-width: 357px;overflow-x: hidden;} </style>
<!--
- JavaScript and HTML must be in separate files: see our Content Security
- Policy documentation[1] for details and explanation.
-
- [1]: http://developer.chrome.com/extensions/contentSecurityPolicy.html
-->
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$( document ).ready(function() {
$( "#fname" ).on( "click", function() {
alert( "HI");
});
});
</script>
</head>
<body>
<table style="width:300px">
<tr>
<td id="fname">Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
</body>
</html>
你能告诉我我做错了什么吗?
【问题讨论】:
标签: jquery google-chrome google-chrome-extension google-chrome-app