我正在制作我的第一个Chrome扩展程序,并在弹出窗口中使用jQuery遇到了问题。当我检查弹出窗口时,我收到错误错误:Uncaught ReferenceError: $ is not defined
虽然我在manifest.json
中包含了我的本地jQuery副本。我能够在popup.js中使用console.log,但是jQuery库显然没有加载。我搜索了相关问题,但无法确定问题 - 请提供建议
的manifest.json
{
"manifest_version":2,
"name":"extension",
"version":"0.1",
"content_scripts":[
{
"matches": [
"<all_urls>"
],
"js":["jquery-3.1.1.min.js","content.js","popup.js"]
}],
"browser_action":{
"default_icon":"icon.png",
"default_popup":"popup.html"
}
,
"background":{
"scripts":["background.js"]
}
}
popup.html
<!DOCTYPE html>
<script src="popup.js"></script>
<div>
Search RT for Movie: <input type="text" value=""><input type="submit" id="bleh">
</div>
popup.js
$(document).ready(function(){
function d(c){
console.log(c)
}
d('hi')
$('#bleh').click(function(){d('bi')})
})
答案 0 :(得分:2)
您需要将jQuery加载到弹出窗口中。您可以为其添加// Using LINQ and just referencing p.Employer will lazy load
// I am not at a computer but I know I have lazy loaded in one
// query with a single query call like below.
List<Person> persons = new List<Person>();
using(MyDbContext dbContext = new MyDbContext())
{
persons = (
from p in dbcontext.Persons
select new Person{
Name = p.Name,
Email = p.Email,
Employer = p.Employer
}).ToList();
}
标记来执行此操作:
popup.html :
<script>