为什么javascript在此代码中不起作用?

时间:2019-07-14 12:58:10

标签: javascript materialize

简单的实现代码不起作用。在chrome和Codepen.io上试用过

我尝试了引导Javascript,并且效果很好/

<!DOCTYPE html>
<html>

<head>
    <title></title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/material-design-icons/3.0.1/iconfont/material-icons.min.css">
    <!-- Compiled and minified JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</head>

<body>
    <ul class="collapsible">
        <li>
            <div class="collapsible-header"><i class="material-icons">filter_drama</i>First</div>
            <div class="collapsible-body"><span>Lorem ipsum dolor sit amet.</span>
            </div>
        </li>
        <li>
            <div class="collapsible-header"><i class="material-icons">place</i>Second</div>
            <div class="collapsible-body"><span>Lorem ipsum dolor sit amet.</span>
            </div>
        </li>
        <li>
            <div class="collapsible-header"><i class="material-icons">whatshot</i>Third</div>
            <div class="collapsible-body"><span>Lorem ipsum dolor sit amet.</span>
            </div>
        </li>
    </ul>
    <script>
        $(document).ready(function(){
            $('.collapsible').collapsible();
        });
    </script>
    <script type="text/javascipt" src="index.js"></script>
    <script type="text/javascipt" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script type="text/javascipt" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</body>

</html>

折叠部分应该起作用。

1 个答案:

答案 0 :(得分:0)

您必须将此移至其他脚本(jQuery等)下方

<script>$(document).ready(function(){
$('.collapsible').collapsible();
});</script>