我需要让用户选择一个值,然后我想生成一个新的 html 页面,该页面将显示所选值。
Step1:应用程序生成一个值列表,用户需要选择一个值(我知道怎么做,我在这个测试中使用了一个简化版本)
Step2:一旦用户单击该值,就会生成一个新的html文件,并且选定的值将显示为文本(我不知道该怎么做)
默认的 html 文件如下(f.html):
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p style="text-align: center;">Test - Step 1</p>
<p style="text-align: center;"> </p>
<p style="text-align: center;"><select id="sel1" style="width: 230px; height: 35px; margin: 0px 0 0px 0;">
<option selected="selected" value="">email</option>
</select></p>
<script>
function listS() {
const selectElem = document.getElementById('sel1');
const index = selectElem.selectedIndex;
if (index > -1) {
const e = document.getElementById("sel1");
const value = e.options[index].value;
const body = { index: index, value: value };
google.script.run.withSuccessHandler(yourCallBack).yourServerSideFunc(body);
}
}
document.getElementById("sel1").addEventListener("click",listS);
function yourCallBack() {
}
</script>
</body>
</html>
js文件是:
function doGet() {
var output = HtmlService.createHtmlOutputFromFile('f');
return output;
}
function yourServerSideFunc(body) {
var value = body["value"];
var output = HtmlService.createHtmlOutputFromFile('f2');
return output;
return ContentService.createTextOutput(JSON.stringify({message: "ok"})).setMimeType(ContentService.MimeType.JSON);
}
新的 html 文件 (f2) 是:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p id="test"style="text-align: center;">Your value is</p>
<p style="text-align: center;"> </p>
</body>
</html>
一旦能够生成新的 html,我需要将文本更改为:“您的值是:”+value。但是我什至无法生成 f2.html。我怎样才能做到这一点?
慕妹3242003
相关分类