我已经使用xul在firefox中添加了工具栏按钮,现在我想在javascript中更改该工具栏按钮的背景颜色。有人请帮忙
我的xul按钮代码是:
<toolbox id="navigator-toolbox">
<toolbar id="TutTB-Toolbar" toolbarname="Tutorial Toolbar" accesskey="T"
class="chromeclass-toolbar" context="toolbar-context-menu"
hidden="false" persist="hidden">
<toolbaritem flex="0">
<toolbarbutton id="TutTB-Web-Button" tooltiptext="Search"
label="button" oncommand="alert('ok');" />
</toolbaritem>
<toolbarspring />
</toolbar>
</toolbox>
我尝试通过以下代码行在javascript中访问它
var p = document.getElementById("TutTB-Web-Button");
alert(p.textContent);
document.getElementById("TutTB-Web-Button").style.backgroundColor='red';
这很可能与xul元素的默认外观有关。你必须做-moz-appearance:none
尝试这样:
在您的CSS中:
.myRedClass{
-moz-appearance: none;
background-color:red;
}
在您的JS中:
document.getElementById("TutTB-Web-Button").classList.add('myRedClass');
结果:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句