Chrome扩展程序' $'在弹出窗口中未定义

时间:2017-01-29 02:17:48

标签: jquery google-chrome google-chrome-extension popup

我正在制作我的第一个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')})
})

1 个答案:

答案 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>