第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Google Web 應用程序 - 從默認 html 文件生成另一個 html

Google Web 應用程序 - 從默認 html 文件生成另一個 html

ibeautiful 2022-10-08 17:55:38
我需要讓用戶選擇一個值,然后我想生成一個新的 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;">&nbsp;</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;">&nbsp;</p>  </body></html>一旦能夠生成新的 html,我需要將文本更改為:“您的值是:”+value。但是我什至無法生成 f2.html。我怎樣才能做到這一點?
查看完整描述

1 回答

?
慕妹3242003

TA貢獻1824條經(jīng)驗 獲得超6個贊

幾點:

  • 您需要一個value,否則 value 為空。

  • yourServerSideFunc(body)有兩個返回值,顯然第二個沒有被執(zhí)行。

  • 如果要將用戶重定向到不同的頁面,請通過重定向來實現(xiàn)。但是如果你想更新基本 html中的內容,那么你可以使用 HTML 元素的 style 屬性來隱藏或顯示元素。

  • 您還可以在您的中實現(xiàn)一些條件doGet(e),并根據(jù)參數(shù)或其集合呈現(xiàn)不同的內容。這將在同一 URL 處生成不同的 HTML。

例如:

1- 用戶訪問您的網(wǎng)絡應用程序,因此doGet()被執(zhí)行。

2-用戶從下拉列表中選擇一個選項,因此瀏覽器偵聽點擊事件并執(zhí)行listS()

3-將返回 HTML 內容listS()的用戶選擇的值傳遞給回調。yourServerSideFuncshowDiv

4-showDiv執(zhí)行并更新 HTML 內容。


代碼.gs

function doGet() {

  var output = HtmlService.createHtmlOutputFromFile('f');

  return output;

}


function yourServerSideFunc(body) {

  console.log(body);

  var value = body["value"];

  var output = HtmlService.createTemplateFromFile('f2');

  output.value = value;

  return output.evaluate().getContent();

}

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;">&nbsp;</p>

    <select id="sel1" style="width: 230px; height: 35px; margin: 0px 0 0px 0;">

        <option selected="selected" value="email">email</option>

    </select>

    <div id="resultDiv" style="display: None;"></div>

    <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(showDiv).yourServerSideFunc(body);

    }

}


function showDiv(value) {

    var resultDiv = document.getElementById("resultDiv");

    resultDiv.innerHTML = value;

    resultDiv.style.display = "Block";

}

document.getElementById("sel1").addEventListener("click", listS);

    </script>

</body>


</html>

f2.html

<p id="test"style="text-align: center;">Your value is</p>

<p style="text-align: center;"><?= value ?></p>

進一步閱讀:

Apps 腳本模板化 HTML


查看完整回答
反對 回復 2022-10-08
  • 1 回答
  • 0 關注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號