這是我在這個(gè)論壇上提出的先前問題的延續(xù)。我通過添加 else 條件對代碼進(jìn)行了一些更改。我想要解決的是在頁面加載時(shí)顯示當(dāng)前狀態(tài)。當(dāng)前代碼僅在單擊按鈕時(shí)顯示狀態(tài)。如何在頁面加載時(shí)顯示當(dāng)前狀態(tài),并在單擊按鈕時(shí)更新狀態(tài)。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>
如何保持狀態(tài)繼續(xù)出現(xiàn)在 JavaScript 函數(shù)到 HTML 上
慕桂英3389331
2023-09-21 17:03:48