Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.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 内容Js功能未链接错误-“;“未定义功能”;_Javascript_Function_Firefox_Firefox Addon_Firefox Addon Sdk - Fatal编程技术网

Javascript 内容Js功能未链接错误-“;“未定义功能”;

Javascript 内容Js功能未链接错误-“;“未定义功能”;,javascript,function,firefox,firefox-addon,firefox-addon-sdk,Javascript,Function,Firefox,Firefox Addon,Firefox Addon Sdk,在Firefox插件上工作时,我调用的是内容js,使用下面的附加脚本的html页面是附加脚本的代码段 var textChk = require("sdk/panel").Panel({ position: { top: 0, right: 0 }, hight: 100, contentURL: data.url("textChk.html"), contentScriptFile: data.url("content.j

在Firefox插件上工作时,我调用的是内容js,使用下面的附加脚本的html页面是附加脚本的代码段

var textChk = require("sdk/panel").Panel({
    position: {
        top: 0,
        right: 0
    },
    hight: 100,
    contentURL: data.url("textChk.html"),
    contentScriptFile: data.url("content.js")
});
function handleClick() {
    textChk.show();
    textChk.port.on("first-para", function(firstPara) {
      console.log(firstPara);
    });
    textChk.port.emit("get-first-para");
}
内容脚本的代码如下所示

function loginChk()
{
    self.port.on("get-first-para", getFirstPara);
}

function getFirstPara() {
    var userId = document.getElementById("usermail").value;
    var pass = document.getElementById("password").value;
    if (userId.length > 0 && pass.length > 0) {
        var firstPara = userId + " ** " + pass;
        self.port.emit("first-para", firstPara);
    }
}
现在,当我调用loginChk()函数时,我得到以下错误

ReferenceError: loginChk is not defined

我无法找出问题出在哪里,因为这在前面的另一个附加代码中起作用。有人能告诉我如何纠正这个错误吗?

我们在IRC上讨论了一下,但仅供将来参考

您可以开始使用“/”作为数据文件夹的快捷方式(因此,您不再需要为这种琐碎的事情使用数据模块);并删除
contentScriptFile

var textChk = require("sdk/panel").Panel({
  position: {
    top: 0,
    right: 0
  },
  hight: 100,
  contentURL: "./textChk.html"
});
“content.js”可以直接包含在“textChk.html”文件中,只需一个脚本标记:

<!-- textChk.html -->
<html>
  <head>
     <!-- meta, etc -->
     <script src="content.js"></script>
  </head>
  <!-- rest of your file, body, etc -->
</html>
这将是一个更好的事件流

也就是说,如果没有真正调用
loginChk
的代码,我就无法判断出问题所在,因为我看不到您的加载项的流程。 我能告诉你的是,如果
loginChk
实际上只添加了一个侦听器,你不需要它,你可以像我一样放置,而不需要将它包装到任何函数中


希望能有所帮助。

您在任何主题上都得到了帮助吗?还没有什么。如果您现在可以在irc上使用,请将链接发送给我。我现在在irc上,但没有空:(但请跳上,我将在45分钟后有空:)
var textChk = require("sdk/panel").Panel({ /* ...*/ });

textChk.port.on("first-para", (firstPara) => console.log(firstPara));

textChk.on("show", () => textChk.port.emit("get-first-para"));

function handleClick() {
  textChk.show();
}