【发布时间】:2011-10-31 17:36:56
【问题描述】:
我有一堆动态生成的 TextBox-es。在创建步骤中,我正在为它们分配 ID 属性。 例如
id = ...
Button b = new Button();
b.setText("add textbox");
b.addClickHandler(new Clickhandler() {
Textbox tb = new TextBox();
tb.getElement().setId(Integer.toString(id));
tb.setText("some text");
}
id += 1;
稍后我需要通过他们的 ID 访问他们,但我不能这样做。 我尝试使用 DOM 对象来获取小部件,但它产生了异常:
String id = "some id";
Element el = DOM.getElementById(id);
String value = el.getAttribute("value"); - this line produces an exception.
我也尝试过使用 el.getInnerText、el.getNodeValue - 不走运。我在 chrome 调试器中看到 - 文本框没有“值”属性。
【问题讨论】: