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

2017年12月31日日曜日

セレクトボックスのオプションを選択状態にする

JavaScriptでセレクトボックスのオプションを選択状態にする




セレクトボックスを作る では
<option value="選択肢2" selected>選択肢2</option>
のようにオプションに直接selectedを入れました

今回はJavaScriptで指定したindexをselectedにしています
document.getElementById("select1").selectedIndex = 1;




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




index.html
<!DOCTYPE html>
<html>
<body>
  <select id="select1">
      <option value="選択肢1">選択肢1</option>
      <option value="選択肢2">選択肢2</option>
      <option value="選択肢3">選択肢3</option>
    </select>
  <script>
    document.getElementById("select1").selectedIndex = 1;
  </script>
</body>
</html>
意訳
これはHTML5文書です


セレクトボックスを置く
1つ目の選択肢
2つ目の選択肢
3つ目の選択肢


1番目の選択肢を選択する(選択肢1は0番目)





Latest post

Google Apps Scriptの障害時はIssueTrackerを見てみる - Incidents for Apps Script are reported on Issue Tracker

IssueTracker > Apps Script issues https://issuetracker.google.com/savedsearches/566234 Google Apps Scriptの障害時は IssueTracker に課題が上がっていることが...