Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery可以';其他.js文件无法访问_Javascript_Google Chrome Extension - Fatal编程技术网

Javascript jQuery可以';其他.js文件无法访问

Javascript jQuery可以';其他.js文件无法访问,javascript,google-chrome-extension,Javascript,Google Chrome Extension,这是一个html页面: <html> <head> <script src="http://code.jquery.com/jquery-1.9.0.min.js" type="text/javascript"></script> </head> <body> <script src="background.js" type="text/javascript"></script>

这是一个html页面:

    <html>
<head>
    <script src="http://code.jquery.com/jquery-1.9.0.min.js" type="text/javascript"></script>
</head>
<body>
    <script src="background.js" type="text/javascript"></script>
</body>
</html>
Alert1工作,但alert2从不播放。如果我删除jQuery,它就会工作。我尝试了background.js文件的头部和正文。我做错了什么


谢谢。

从下载
jquery.js
,并将其内联到扩展目录中,如图所示内联引用

根本原因 Chrome扩展不支持对文件的外部引用

工作版本 background.js 你的代码和以前一样

alert("Alert1!");
var test = jQuery.trim(" Words and / { objects & things");
alert("Alert2!" + test);

我能够用以下清单和代码来警告修剪后的值

显示

{
  "name": "Tester",
  "version": "0.1",
  "manifest_version": 2,
  "background":{
    "page":"background.html",
    "persistent": false
  }
}
background.html

<html>
<head>
</head>
<body>
    <script src="jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="background.js" type="text/javascript"></script>
</body>
</html>

实际上我已经试过了,但没有效果:@Slappybag:你指的HTML页面是什么?如果有相关的代码,你能分享吗?我唯一能补充的是,它是从manifest.json引用的。否则,我就把所有的东西都剥掉了,一切都是这样<代码>代码“背景”:{“页面”:[background.html]},@Slappybag:我看到你想在你的
背景页面中使用jquery,不是吗?@Slappybag:检查我的编辑1,你可以添加jquery,如我的回答所示。这实际上不起作用,jquery仍在杀死脚本=/不,这确实起作用。你正在做的事情就是杀死脚本。
alert("Alert1!");
var test = jQuery.trim(" Words and / { objects & things");
alert("Alert2!" + test);
{
  "name": "Tester",
  "version": "0.1",
  "manifest_version": 2,
  "background":{
    "page":"background.html",
    "persistent": false
  }
}
<html>
<head>
</head>
<body>
    <script src="jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="background.js" type="text/javascript"></script>
</body>
</html>
var test = jQuery.trim(" Words and / { objects & things");
alert(test);