[英]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.