2011-02-09 42 views
2

我想爲我的擴展程序添加一個檢查菜單項。火狐擴展中的複選框

<menupopup id="menu_ToolsPopup"> 
    <menuitem type="checkbox" label="Convert" id="menu_ToolsPopupItem"/>  
</menupopup> 

overlay.js中

window.addEventListener("load", function() {myExtension.init()}, false); 
init: function() {   
     window.addEventListener("copy", function() {myExtension.Test()}, false);  
}, 

    Test: function (win) {  
    var x= document.getElementById("menu_ToolsPopupItem"); //not null!!! alert(x)=> [object XULElement] 
    alert(x.checked);//-> undefined 
} 

我不明白的菜單項的狀態。

以及如何在重新啓動瀏覽器後保存選擇?

回答

0

看起來你必須訪問屬性 - 有在這種情況下,沒有方便的屬性包裝:

[attribute] checked 
    Type: boolean 
    Indicates whether the element is checked or not. 
    Use hasAttribute() to determine whether this attribute is set instead of getAttribute(). 

https://developer.mozilla.org/en/XUL/menuitem#a-checked


而且我怎麼保存選擇後,我重新啓動瀏覽器?

有很可能有幾種不同的方法。首先想到的是將其存儲在首選項中。 https://developer.mozilla.org/en/Code_snippets/Preferences

+0

謝謝,我的第二個問題呢? – urker 2011-02-09 16:51:16

0

從歷史上看,原因菜單項通常沒有屬性包裝的屬性是有一些情況下,他們沒有工作。我不知道這是否仍然如此。

要在重新啓動時保留菜單項的checked屬性,最簡單的方法是添加persist="checked"屬性。

相關問題