admin管理员组文章数量:1315960
I am having trouble initializing some Materialize-css javascript functions; the one in particular is material_select().
I am trying to initialize the function as stated in the Materialize docs:
$(document).ready(function() {
$('select').material_select();
});
However, I get the following error:
$(...).material_select is not a function
material_select()
as well as any other Materialize function initializes if I manually write it into the browser console, but not if it's in the code; I am importing jQuery before materialize.js as well.
Help is much appreciated, thank you.
I am having trouble initializing some Materialize-css javascript functions; the one in particular is material_select().
I am trying to initialize the function as stated in the Materialize docs:
$(document).ready(function() {
$('select').material_select();
});
However, I get the following error:
$(...).material_select is not a function
material_select()
as well as any other Materialize function initializes if I manually write it into the browser console, but not if it's in the code; I am importing jQuery before materialize.js as well.
Help is much appreciated, thank you.
Share Improve this question asked Dec 7, 2016 at 18:38 Lane FujikadoLane Fujikado 1351 gold badge3 silver badges11 bronze badges3 Answers
Reset to default 3You are most likely loading materialize.js before jQuery or your jQuery version is too high and not working with materialize. You need to add some code here!
Double check that jQuery and Materialize are initialized before the document ready function is called.
For example:
<script type="text/javascript" src="https://code.jquery./jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
<script>
$(document).ready(function() {
$('select').material_select();
});
</script>
And of course make sure that the appropriate CSS files are imported in <head>
It is impossible to give the exact solution without referring your code. Problem may be happened in the materialize.js
file. It would be better if you test following fully working code and find your issue.
Working code
Click Run Code Snippet
in the given link for live demo or copy full code and test in your machine.
本文标签: javascriptInitializing Materialize functionsStack Overflow
版权声明:本文标题:javascript - Initializing Materialize functions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741985159a2408632.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论