我使用 html 页面在 Google 脚本中创建了一个表单,然后调用 javascript 函数,如此处所述。当我运行应用程序时,表单加载得很好,但它不会执行脚本。我怎样才能使这项工作?
这是我正在尝试做的一个例子:
<html>
<!--Create Sign Out Form-->
<form id="signOut">
<div>
Destination:
<select name="destination">
<option value="lunch">Lunch</option>
<option value="meeting">Client Meeting</option>
<option value="vacation">Vacation</option>
<option value="sick">Out Sick</option>
<option value="personal">Personal</option>
<option value="home">Working from Home</option>
<option value="scedule">Reduced Schedule</option>
</select>
</div>
<div>
Supervisor:
<select name="supervisor" onselect="google.script.run.withUserObject(this.parentNode).populate(destination)"></select>
</div>
<div>
Start Date:
<input type="date" name="startDate" onselect="google.script.run.withUserObject(this.parentNode).SignOutLibrary.dateSelect()"/>
</div>
<div>
End Date:
<input type="date" name="endDate" onselect="google.script.run.withUserObject(this.parentNode).SignOutLibrary.dateSelect()"/>
</div>
<div>
Details:
<textarea type="text" name="details" style="width: 150px; height: 75px;"></textarea>
</div>
<div>
<input type="button" value="Submit"
onclick="google.script.run
.sendRequest(this.parentNode)"/>
</div>
</form>
</html>
它应该调用的脚本:
function doGet() {
// Uses html form
return HtmlService.createHtmlOutputFromFile('request_form');
}
签出库:
function dateSelect() {
var app = UiApp.createApplication();
var handler = app.createServerHandler("change");
var date = app.createDatePicker().setPixelSize(150, 150).addValueChangeHandler(handler).setId("date");
app.add(date);
return app;
}
function change(eventInfo) {
var app = UiApp.getActiveApplication();
app.add(eventInfo.parameter.date);
return app;
}