Javascript 在(";show";,function())上不';我不能在FF扩展中工作

Javascript 在(";show";,function())上不';我不能在FF扩展中工作,javascript,firefox-addon,Javascript,Firefox Addon,我有FF扩展,其中在显示面板时,事件焦点应自动位于文本输入字段参数。我在(“show”,function())(在scrip.js中)上使用,但是无论我在这个函数中插入什么,它都不起作用 有什么建议吗 main.js: var panel = panels.Panel({ contentURL: self.data.url("index.html"), contentScriptFile: self.data.url("script.js"), onHide: handl

我有FF扩展,其中在显示面板时,事件焦点应自动位于文本输入字段
参数
。我在(“show”,function())(在
scrip.js
中)上使用
,但是无论我在这个函数中插入什么,它都不起作用

有什么建议吗

main.js:

var panel = panels.Panel({
    contentURL: self.data.url("index.html"),
    contentScriptFile: self.data.url("script.js"),
    onHide: handleHide,
    width: 250,
    height: 200
});

function handleChange(state) {
    if (state.checked) {
        panel.show({
            position: button
        });
    }
}
self.port.on("show", function onShow() {
    document.getElementById("parameter").focus();
});
script.js:

var panel = panels.Panel({
    contentURL: self.data.url("index.html"),
    contentScriptFile: self.data.url("script.js"),
    onHide: handleHide,
    width: 250,
    height: 200
});

function handleChange(state) {
    if (state.checked) {
        panel.show({
            position: button
        });
    }
}
self.port.on("show", function onShow() {
    document.getElementById("parameter").focus();
});

show
是一个事件,它被发送到
面板上(“eventname”)
回调。
端口
用于插件上下文和面板上下文之间的消息传递

例如,
panel.port.on(…)
panel.on(…)
不同


而且它在面板上下文中不可用。也许您可以为此使用pageshow/pagehide dom事件,或者您可以通过端口将事件从插件反映到面板。

将以下代码添加到
main.js
帮助:

panel.on("show", function() { 
    panel.port.emit("show");
});

非常感谢。我在
main.js
中添加了以下代码,现在可以使用了:
panel.on(“show”,function(){panel.port.emit(“show”);})