Element.getStyle()不返回GWT中的任何值 [英] Element.getStyle() does not return any value in GWT
问题描述
我的CSS文件为stylemyButton设置宽度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,且元素大小已正确调整为100像素。
为什么测试没有任何值?
感谢,
MyFile。 html
< div style =width:100%>
< a id =myButtonhref =#class =myButtonstyle =text-decoration:none>嘿< / a>
< / div>
MyFile.css
$ b b.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;
}
解决方案其
Element#getStyle()
返回与JavaScript的element.style
相同的值,即将 inline <style =
GWT不会模拟
getComputedStyle
或类似的;如果你真的需要它们(这是不太可能的;你应该重构代码),那么你必须使用JSNI。
查看 https://developer.mozilla.org/en/DOM/element.style
My CSS file below sets width "50px" for style "myButton", and accordingly the element is correctly created with width 50px.
The issue is managing the element from Java (GWT). The following lines:
MyFile.java
final Element box1 = DOM.getElementById("myButton"); String test=box1.getStyle().getWidth(); box1.getStyle().setWidth(100, Unit.PX); String test2=box1.getStyle().getWidth();
have as a result test="" and test2="100px", and element is correctly resized to 100px. Why doesn't test have any value?
Thanks,
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; }
解决方案
Element#getStyle()
returns the same as JavaScript'selement.style
, i.e. the style applied inline to the element (via itsstyle=""
attribute).GWT does not emulate
getComputedStyle
or similar; if you really need them (which is unlikely; you should probably refactor your code instead), then you'll have to use JSNI.See https://developer.mozilla.org/en/DOM/element.style
这篇关于Element.getStyle()不返回GWT中的任何值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!