簡體   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