gpt4 book ai didi

java - Element.getStyle() 在 GWT 中不返回任何值

转载 作者:太空宇宙 更新时间:2023-11-04 05:05:23 26 4
gpt4 key购买 nike

我下面的 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。为什么测试没有任何值(value)?

谢谢,

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() 返回与 JavaScript 的 element.style 相同的内容,即应用内联到元素的样式(通过它的 style="" 属性)。

GWT 不模拟 getComputedStyle 或类似的;如果你真的需要它们(这不太可能;你可能应该重构你的代码),那么你将不得不使用 JSNI。

参见 https://developer.mozilla.org/en/DOM/element.style

关于java - Element.getStyle() 在 GWT 中不返回任何值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10572697/

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