Apps Scriptリファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2019年12月7日土曜日

JSでボタンを押し続けてカウントアップしたい








コード.gs
function doGet() {
  return HtmlService.createHtmlOutputFromFile("index");
}
意訳
この機能がやること
指定したHTMLファイルを表示する




index.html
<!DOCTYPE html>
<html>
  <body>
    <label id="count">1</label>
    <br>
    <button id="nextBt">+</button>
    <button id="prevBt">-</button>

    <script>    
      var timer;
    
      elem("nextBt").onmousedown = nextKeydown;
      elem("nextBt").onmouseup = nextKeyup;
      elem("prevBt").onmousedown = prevKeydown;
      elem("prevBt").onmouseup = prevKeyup;
    
      function elem(id) {
        return document.getElementById(id);
      }
    
      function nextKeydown() {
        timer = setInterval(function() { setCount(1) }, 100);
      }
    
      function nextKeyup() {
        clearInterval(timer);
      }
    
      function prevKeydown() {
        timer = setInterval(function() { setCount(-1) }, 100);
      }
    
      function prevKeyup() {
        clearInterval(timer);
      }

      function setCount(num) {
        elem("count").textContent = parseInt(elem("count").textContent) + num;
      }
    </script>
  </body>
</html>




Latest post

Googleドライブ内の音声ファイルをiframe内で再生したい

iframe の src にGoogleドライブ内の音声ファイルを埋め込む例です (今回試した音声ファイルはmp3) Code.gs function doGet () { return HtmlService . createTemplateFromFile ( ...