Javascript 如何在chrome扩展名中包含jquery文件
我想使用jquery在chrome扩展中输入checkbox的值,但是 给我的是错误: 未定义$ 我下载jquery文件并保存在文件夹中,并在manifest.json中给出jquery文件的路径,但仍然会出现相同的错误。所以我想知道什么是包含jquery文件的正确方法 我这样写:Javascript 如何在chrome扩展名中包含jquery文件,javascript,jquery,Javascript,Jquery,我想使用jquery在chrome扩展中输入checkbox的值,但是 给我的是错误: 未定义$ 我下载jquery文件并保存在文件夹中,并在manifest.json中给出jquery文件的路径,但仍然会出现相同的错误。所以我想知道什么是包含jquery文件的正确方法 我这样写: { "name": "Chrome Extension Test", "version": "1.0", "description": "Chrome extension to investi
{
"name": "Chrome Extension Test",
"version": "1.0",
"description": "Chrome extension to investigate Etsy product listings.",
"permissions": [
"storage",
],
"browser_action": {
"default_icon": {
"16": "images/get_started16.png"
},
"default_popup": "background.html",
"icons": {
"16": "images/get_started16.png"
},
"default_title": "Seller Tools"
},
"background": {
"scripts": [
"background.js", "js/jquery/jquery.js"
],
"persistent": false
},
"manifest_version": 2
}
我在background.js中编写的全部代码
Jqueryincluding$用于任何功能,所以它给了我一个错误$
没有定义,我面临着很大的困难。也不是
允许我写。您可以将其包含在HTML文档的head标记中,而不是.js或.json文件中
<head>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
</head>
然后,您可以在HTML文档中的任何位置使用jquery。如果您几乎正确地使用jquery,则只需修改脚本顺序。您正在内容脚本中使用jQuery,因此应首先加载jQuery:
{
"name": "Chrome Extension Test",
"version": "1.0",
"description": "Chrome extension to investigate Etsy product listings.",
"permissions": [
"storage",
],
"browser_action": {
"default_icon": {
"16": "images/get_started16.png"
},
"default_popup": "background.html",
"icons": {
"16": "images/get_started16.png"
},
"default_title": "Seller Tools"
},
"background": {
"scripts": [
"js/jquery/jquery.js", "background.js"
],
"persistent": false
},
"manifest_version": 2
}
特别是对于Chrome扩展,这还不够——jQuery确实必须从那里的清单文件中引用。