亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

如何保持狀態繼續出現在 JavaScript 函數到 HTML 上

如何保持狀態繼續出現在 JavaScript 函數到 HTML 上

慕桂英3389331 2023-09-21 17:03:48
這是我在這個論壇上提出的先前問題的延續。我通過添加 else 條件對代碼進行了一些更改。我想要解決的是在頁面加載時顯示當前狀態。當前代碼僅在單擊按鈕時顯示狀態。如何在頁面加載時顯示當前狀態,并在單擊按鈕時更新狀態。CODE.GSfunction doGet(e) {  return HtmlService.createHtmlOutputFromFile('Index');}function checkStatus(notify) {   var employee = "John Peter";  var ss = SpreadsheetApp.getActiveSpreadsheet();          var mainSheet = ss.getSheetByName("MAIN");  var data = mainSheet.getDataRange().getValues();    for (var j = 0; j < data.length; j++){    var row = data[j];    var mainSheet2 = row[4];    var mainSheet3 = row[0];    var status = (mainSheet2 =="IN" && mainSheet3 == employee) ;     if (status == true){      var notify = employee +" You Are In"      return notify;      }    else{     var status = (mainSheet2 =="OUT" && mainSheet3 == employee) ;     if (status == true){      var notify2 = employee +" You Are Out"      return notify2;  }}  }}索引.html<body>    <div>      <button onclick="onStatus()">Check Status</button>      <font color='Green' id="status" onbeforeprint="onStatus" ></font>      </div>              <script>      function onStatus() {        google.script.run.withSuccessHandler(updateStatus) // Send the backend result to updateStatus()          .checkStatus(); // Call the backend function      }      function updateStatus(notify) {        document.getElementById('status').innerHTML= notify;      }                     </script>  </body>
查看完整描述

1 回答

?
眼眸繁星

TA貢獻1873條經驗 獲得超9個贊

您可以在頁面加載時調用此函數,如下所示。在正文標記結束之前添加此腳本。


<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">

</script>

<script>

    // The code in this function runs when the page is loaded.

    $(function() {

     google.script.run.withSuccessHandler(updateStatus)

              .checkStatus(); 

    });

</script>


查看完整回答
反對 回復 2023-09-21
  • 1 回答
  • 0 關注
  • 110 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號