0

以下の私のCSSファイルは、スタイル「myButton」の幅「50px」を設定しているため、要素は幅50pxで正しく作成されます。

問題は、Java(GWT)からの要素の管理です。次の行:

MyFile.java

final Element box1 = DOM.getElementById("myButton");
String test=box1.getStyle().getWidth();
box1.getStyle().setWidth(100, Unit.PX);
String test2=box1.getStyle().getWidth();

結果としてtest=""test2="100px"があり、要素は100pxに正しくサイズ変更されます。テストに価値がないのはなぜですか?

ありがとう、

MyFile.html

<div style="width: 100%"> 
  <a  id ="myButton" href="#" class="myButton" style="text-decoration: none">Hey</a>    
</div>

MyFile.css

.myButton {
    display:block;
    padding: 10px;
    font-family:"Garamond 3 W01","Franklin Gothic Medium", "Arial Narrow", Arial, sans-serif;/*"Lucida Sans", "Lucida Sans Regular", "Lucida Grande", "Lucida Sans Unicode", Geneva, Verdana, sans-serif;*/
    font-size: medium;
    color: #000000;
    text-align: center;
    border-radius: 8px;
    background-color: #E7E7E7;
    background-image: url('bar1.png');
    border-bottom: 1px solid #BBB;
    border-top: 1px solid #BBB;
    box-shadow: 0 0 6px 0 #B3B2B7;
    text-shadow: 0 1px 0 white;
    width: 50px; 
    height: 30px;
    margin: 10px 10px 10px 10px;
}
4

1 に答える 1

1

Element#getStyle()JavaScriptと同じものを返します。つまり、要素にインラインelement.styleで適用されたスタイル(属性を介して)を返します。style=""

GWTはエミュレートgetComputedStyleまたは類似していません。それらが本当に必要な場合(これはありそうにありません。代わりにコードをリファクタリングする必要があります)、JSNIを使用する必要があります。

https://developer.mozilla.org/en/DOM/element.styleを参照してください

于 2012-05-13T21:04:07.847 に答える