GWT TextArea的最大长度

Del*_*ari 10 gwt

我无法设置GWT TextArea的最大长度.有人可以帮助我在GWT中实现这一目标吗?

TextArea t1 = new TextArea();
t1.setMaxLength(300); // This method doesn't exist. How do I do this?
Run Code Online (Sandbox Code Playgroud)

Mah*_*ore 14

Gal的答案是正确的,只有一次更正:

t1.getElement().setAttribute("maxlength", "100");
Run Code Online (Sandbox Code Playgroud)

第二个参数是一个字符串.这对我有用.


Gal*_*cha 6

您可以这样设置:

t1.getElement().setAttribute("maxlength", "100");
Run Code Online (Sandbox Code Playgroud)


And*_*rle 3

其原因是 maxLength 是 html5 的一项功能,因此它无法在旧版浏览器中工作。你必须自己做。只需添加一个 keyPresshandler 并计算文本区域中文本的长度,如果文本太长则剪切文本。