简体   繁体   English

在 Google App 脚本上初始化 `Materialize` select

[英]Initializing `Materialize` select on Google App Script

I am trying to write a basic form that includes a select element with the Materialize framework .我正在尝试使用Materialize框架编写一个包含select元素的基本表单。

However, the select element does not appear to be getting initialized.但是, select元素似乎没有被初始化。

Here is my code (based on the example here ):这是我的代码(基于此处的示例):

<html>

  <head>
    <!--Import Google Icon Font-->
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <!--Import materialize.css-->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
    <!--Let browser know website is optimized for mobile-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  </head>

  <body>
    
    <form class="main" id="form" novalidate="novalidate" style="max-width: 400px;margin: 40px auto;">

    <!-- Account  -->
    <div class="input-field col s12">
      <select>
        <option value="" disabled selected>Choose your option</option>
        <option value="1">Option 1</option>
        <option value="2">Option 2</option>
        <option value="3">Option 3</option>
      </select>
      <label>Materialize Select</label>
    </div>

    </form>
  
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js">
    </script>


    <!--Initialize `select` elements-->
    <script>
      document.addEventListener('DOMContentLoaded', function() {
      var elems = document.querySelectorAll('select');
      var instances = M.FormSelect.init(elems, options);
    });
    </script>

  </body>
</html>

The problem was trivial: options was undefined.问题很简单: options未定义。 Removing it, as in the following line fixes things:删除它,如以下行修复问题:

var instances = M.FormSelect.init(elems);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM