![](/img/trans.png)
[英]How to include jQuery in my manifest.json file for a chrome Extension
[英]how to include the jquery file in chrome extension
我想要使用jquery在chrome擴展中的checkbox的值,但這給了我錯誤:
“未定義$”
我下載了jquery文件並保存在文件夾中,並在manifest.json
提供了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": [
"background.js", "js/jquery/jquery.js"
],
"persistent": false
},
"manifest_version": 2
}
整個代碼是我在background.js中編寫的,但是當我為任何功能編寫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
}
您可以將其包含在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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.