繁体   English   中英

Javascript: Firefox 插件,在里面调用 function

[英]Javascript: Firefox addon, calling a function inside

在我的 button.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]显示警报“测试!” 但如果我将其更改为CustomButton[test]它不会显示警报“正在测试!”

这是为什么?? 相反,它给了我一个错误“测试未定义”

您正在通过变量test而不是字符串"test"

test可能是undefined

任何一个:

CustomButton['test']();

或者

CustomButton.test();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM