Firefox插件,在里面调用一个函数



在我的按钮。xul文件如下:

      <script type="application/x-javascript"
  src="chrome://mf_unblocker/content/button.js"/>
<toolbarbutton id="custom-button-1"
  label="Custom"
  tooltiptext="MAFIAAFire: Slash Unblocker!"
  oncommand="CustomButton[1]()"
  class="toolbarbutton-1 chromeclass-toolbar-additional mf_unblocker"
  />

那么在我的button .js文件中我有这样的内容:

var CustomButton = {
1: function () {
alert("test!");
  },
test: function () {alert("testing!");},
}

在xul文件中,此CustomButton[1]会显示警报"test!",但如果我将其更改为CustomButton[test],则不会显示警报"testing!"

为什么??它反而给了我一个错误"test is not define"

您传递的是变量 test,而不是字符串 "test"

test可能是undefined

:

CustomButton['test']();

CustomButton.test();

最新更新