我想在 google.script.run 運行時捕獲它,因此我可以阻止用戶多次單擊并激活該功能。
這樣的事情可能嗎?
while(google.script.run.function()){
alert("Wait for the function to finish")
}
uj5u.com熱心網友回復:
禁用按鈕:
function lfunko() {
return "Button is disabled"
}
function launchMyDialog() {
const html = '<input type="button" id="btn" value="Click Me" onclick="myfunk();" /><div id="msg"></div><script>function myfunk(){document.getElementById("btn").disabled = true;google.script.run.withSuccessHandler((msg) => {document.getElementById("msg").innerHTML = msg;}).lfunko();}console.log("Code");</script>';
SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html),"Sample Dialog")
}
演示:

uj5u.com熱心網友回復:
我使用了@Cooper 建議并停用了客戶端單擊按鈕,并在功能結束后再次激活它。變成這樣:
HTML
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<button id="btn">BUTTON</button>
<?!= include('javascript'); ?>
</body>
</html>
javascript.html
document.getElementById("btn").addEventListener("click",click);
function click(){
google.script.run.withSuccessHandler(table).doSomething();
document.getElementById("btn").disabled=true;
}
function table() {
document.getElementById("btn").disabled=false;
}
代碼.gs
function doSomething(){
Logger.log("Hello");
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/518334.html
