有没有办法用当前日期预先填充它?
以下代码执行所需。
var now = new Date();
var labelDate = app.createLabel("Date of event:");
var textBoxDate = app.createDateBox().setName("date").setStyleAttribute("color", "#a7a7a7").setValue(now);
有没有办法将年份与选择的日期分开?
请通过写作说明您期望拥有isolating the year from the date picked
什么?您需要提取日期的年份吗?如果是,则以下操作。
function doGet(e) {
var app = UiApp.createApplication();
var now = new Date();
app.add(app.createLabel('Current Year: ' + now.getFullYear()));
return app;
}
从日期框中提取年份的代码。
function doGet(e) {
var app = UiApp.createApplication();
var now = new Date();
var dateBox = app.createDateBox().setName('datebox').setValue(now);
var label = app.createLabel(now).setId('label');
var handler = app.createServerHandler('onBtnClick');
handler.addCallbackElement(dateBox);
var btn = app.createButton('Click Me').addClickHandler(handler);
app.add(dateBox);
app.add(label);
app.add(btn);
return app;
}
function onBtnClick(e) {
var selectedDate = new Date(e.parameter.datebox);
var year = selectedDate.getFullYear();
var app = UiApp.getActiveApplication();
var label = app.getElementById('label');
label.setText('Selected Date: ' + selectedDate + ', Year: ' + year);
return app;
}