LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Saturday, December 7, 2019

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

スプレッドシートA列にある複数のテキストをスライドに追加したい(Google Apps Script)

今回Google Apps Scriptでやりたいこと GoogleスプレッドシートA列にある複数の値を取得して Googleスライドに渡して 図形オブジェクトのテキストとして追加したい ① スプレッドシートのA列に値を入れておく ② Code.gsのinsertNewShape...