Q1:我不能完全回答,但看起来您可以使用 、 或 将大多数元素设置为百分比宽度setWidth
和setHeight
高度setSize
。
Q2:您要做的是设置一个 onFocus 处理程序,以便在用户单击该字段时文本消失(此操作称为“聚焦”元素)。这可以通过 ClientHandler 完成,这意味着它会很快。
var text = app.createTextBox().setId("textbox").setName("textbox")
.setStyleAttribute("color","gray").setValue("Input text here");
var focusHandler = app.createClientHandler().forEventSource().setText("")
.setStyleAttribute("color","black");
text.addFocusHandler(focusHandler);
如果用户将该字段留空,您可以将其更改回原始文本并再次将其着色为灰色,但这次您必须使用 ServerHandler,因为我们需要检查该字段是否为空白。此外,离开现场被称为“模糊”。
var blurHandler = app.createServerHandler("textboxBlurred").addCallbackElement(text);
text.addBlurHandler(blurHandler);
...
function textboxBlurred(e) {
var app = UiApp.getActiveApplication();
if (e.parameter.textbox=="") {
var box = app.getElementById("textbox");
box.setValue("Input text here");
box.setStyleAttribute("color", "gray");
}
return app;
}