从 GWT 修改样式 [英] Modify Style from GWT

查看:25
本文介绍了从 GWT 修改样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我执行但只有 FF 和 chrome 将 textarea 从顶部移动 0px 和从左侧移动 0px 但在 IE 中textarea 处于默认位置.

I executed but only FF and chrome moves the textarea 0px from top and 0px from left but in IE textarea is in default position.

这是我的代码:

public class MyGWT implements EntryPoint {

   TextArea ta= TextArea.wrap(DOM.getElementById("t"));

   public void onModuleLoad() {

     ta.getElement().setAttribute("style", "position:absolute;top:0px;left:0px;");
   }

}

是否有任何错误或如何从 GWT 以编程方式更改样式属性??

is there any bug or how can i change style attribute programmatically from GWT ??

推荐答案

不要通过 setAttribute 设置 style.在 JavaScript 中,style 属性实际上是一个数组.因此,根据浏览器的智能程度和理解您想要设置的样式属性,它可以通过设置 style 来工作或不起作用.

Don't set style via setAttribute. In JavaScript the style attribute is actually an array. Thus depending on how smart the browser is and understands you want to set the style attributes it will work by setting style or won't work.

您应该通过getElement().getStyle().setProperty() 单独设置样式属性.或者使用特定的方法,例如:ta.getElement().getStyle().setPosition(Position.ABSOLUTE) 或通过 setProperty 方法:ta.getElement().getStyle().setProperty("position", "absolute").其他 2 个属性也是如此.请参阅 Style 类以了解支持哪些特定方法.

You should set style attributes individually via getElement().getStyle().setProperty(). Or use the specific methods, like: ta.getElement().getStyle().setPosition(Position.ABSOLUTE) or via the setProperty method: ta.getElement().getStyle().setProperty("position", "absolute"). And the same for the 2 other properties. See the Style class for what specific methods are supported.

这篇关于从 GWT 修改样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆