簡體   English   中英

Google Apps 腳本 - 表單輸入未正確提交

[英]Google Apps Script - Form inputs not submitting properly

<form id="colours" onsubmit="doSomething()">
  <label for="startcolour" style="font-family:arial">Start:</label>
  <input type="color" name="startcolour" id="startcolour" value="#123456"> &nbsp;
  <label for="endcolour" style="font-family:arial">End:</label>
  <input type="color" name="endcolour" id="endcolour" value="#abcdef"><br><br>
  <br>
  <input type="submit" value="Submit">
</form>

<script>
  var startcolour = document.getElementById("startcolour").value;
  var endcolour = document.getElementById("endcolour").value;

  function doSomething() {
    google.script.run.withFailureHandler(function(error) {
      console.log("error")
      console.log(error.message)
    }).withSuccessHandler(function(result) {
      console.log("done!")
    }).test(startcolour);
  }
</script>

我有一個 Google Apps Script HTML 側邊欄。 這是 HTML 側邊欄的一些代碼。 當我輸入顏色並按“提交”時,我希望它以提交的 startcolour 值作為輸入運行 test() 函數。 但是,它使用默認值“#123456”運行,而不是用戶提交的值。 我該如何解決?

問題是您正在從 doSomething 函數外部定義“startcolour”和“endcolour”變量,因此當調用該函數時,它使用頁面加載時定義的值,而不是您可以使用的值定義何時提交表單。

解決方案是在 doSomething 函數中定義變量“startcolour”和“endcolour”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM