javascript – Materialise material_select不是函数错误

这是我第一次在这里提问,因为我无法找到问题的答案.我正在使用materialize并尝试使用material_select().这是我的主页面,其中包含jQuery和materialize库以及对sidenav()和material_select()的document.ready调用. Sidenav工作正常,但material_select()正在抛出一个Uncaught TypeError.

<script src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
<script>
$(document).ready(() => {
    $("#slide-out").sidenav();
    $("select").material_select();
});
</script>

这是我使用select的html:

<div class="row">
    <div class="input-field">
        <select name="status" id="selectedTest">
            <option value="public" selected>Public</option>
            <option value="private">Private</option>
            <option value="unpublished">Unpublished</option>
        </select>
        <label for="status">Status</label>
    </div>
</div>

这是我得到的错误:

Uncaught TypeError: $(…).material_select is not a function
at HTMLDocument.$.ready (dashboard:80)
at mightThrow (jquery-3.2.1.js:3583)
at process (jquery-3.2.1.js:3651)

解决方法:

它应该是formSelect()而不是material_select(),因为你使用1.0.0如果我没有错,根据Docs

$(document).ready(function() {
  $("#slide-out").sidenav();
  $("#selectedTest").formSelect();
});
Here is the html where I use select:

<div class="row">
  <div class="input-field">
    <select name="status" id="selectedTest">
      <option value="public" selected>Public</option>
      <option value="private">Private</option>
      <option value="unpublished">Unpublished</option>
    </select>
    <label for="status">Status</label>
  </div>
</div>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">

<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
上一篇:dubbo异步与一致性hash负载均衡


下一篇:javascript – 实现CSS在表单字段上显示错误