1

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';
4

1 に答える 1

0

ほとんどの場合、これは xul 要素のデフォルトの外観に関係しています。あなたがしなければなりません-moz-appearance:none

このようにしてみてください:

あなたのCSSで:

.myRedClass{
    -moz-appearance: none;
    background-color:red;
}

あなたのJSで:

document.getElementById("TutTB-Web-Button").classList.add('myRedClass');

結果:

ここに画像の説明を入力

于 2013-11-11T10:37:51.877 に答える