Chrome 扩展程序“$ 未定义"错误 [英] Chrome extension "$ is not defined" error

查看:30
本文介绍了Chrome 扩展程序“$ 未定义"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在处理 chrome 扩展程序时收到错误$ 未定义".

I am getting an error "$ is not defined" when I am working on my chrome extension.

这是我的清单文件:

   {
      "name": "X",
      "description": "Snip this page",
      "version": "2.0",
      "permissions": [
        "activeTab"
      ],
      "background": {
        "scripts": ["background.js"],
        "persistent": false
      },
      "content_scripts":[{
        "matches" : ["<all_urls>"],
        "js": ["jquery-2.0.2.js","jquery.Jcrop.js"],
        "css": ["jquery.Jcrop.min.css"]
      }],
      "browser_action": {
        "default_title": "Snip this page"
      },
      "manifest_version": 2
    }

这是我的 background.js 文件:

This is my background.js file:

chrome.browserAction.onClicked.addListener(function(tab){
  // No tabs or host permissions needed!
  chrome.tabs.executeScript({
    file: 'content.js'
  });
});

最后是触发错误的文件:content.js

Lastly, the file where the error is triggered: content.js

console.log('1');
var jcropapi, boundx, boundy;
$('body').attr('id', 'target');
$(document).ready(function(){
    $('target').Jcrop();
    console.log('4');
    document.onkeydown = function(){
        if(window.event.keyCode==13){
            console.log('enter');
        }
    };
});

据我所知,这是因为 JQuery 没有被加载.但是,我在清单中正确加载了它,并且 jquery.js 也是清单内容脚本中调用的第一个文件.请帮我调试.谢谢!

From my understanding, this happends because JQuery does not get loaded. However, I am loading it properly in the manifest, and jquery.js is also the first file that gets called in the manifest content script. Please help me in debugging. Thank You!

推荐答案

我不知道它是如何工作的,但是不知何故,当我将 JQuery 更改为其最小化版本并且现在可以工作时.

I have no idea how it works, but somehow, when I changed JQuery to its minimized version and it works now.

这篇关于Chrome 扩展程序“$ 未定义"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆