gpt4 book ai didi

javascript - Firefox 扩展中的复选框

转载 作者:行者123 更新时间:2023-11-30 06:47:33 30 4
gpt4 key购买 nike

我想为我的扩展程序放置一个带有支票的菜单项。

<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
}

我不了解菜单项的状态。

以及如何在重新启动浏览器后保存选择?

最佳答案

看起来您必须访问该属性——在这种情况下没有方便的属性包装器:

[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


and also how do I save the selection after I restart the browser?

很可能有几种不同的方法。第一个想到的是将其存储在首选项中。 https://developer.mozilla.org/en/Code_snippets/Preferences

关于javascript - Firefox 扩展中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4945518/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com