MaterializeCss模式错误openModal不是函数

Ric*_*ore 3 javascript jquery materialize material-design

我有所有要求Jquery,Materialize.js坐在我的Js文件上面然而我得到警告openModal不是一个函数..我检查模态名称是对的,我可以运行Materialize.toast所以我知道Materialise.js正在工作.使用按钮触发也不会调用模态.这是代码..

脚本:

<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="/js/materialize.js"></script>
<script type="text/javascript" src="/js/video.js"></script>
<script src="/js/admin.js"></script>
Run Code Online (Sandbox Code Playgroud)

触发:

<button data-target="modal1" class="btn modal-trigger">Modal</button>
Run Code Online (Sandbox Code Playgroud)

莫代尔:

    <!-- Modal Structure -->
    <div id="modal1" class="modal">
        <div class="modal-content">
            <h4>Modal Header</h4>
            <p>A bunch of text</p>
        </div>
        <div class="modal-footer">
            <a href="#!" class=" modal-action modal-close waves-effect waves-green btn-flat">Agree</a>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

JS:

 var modal = document.getElementById('modal1');
  modal.openModal();
$('#modal1').leanModal();
$('#modal1').openModal();
Run Code Online (Sandbox Code Playgroud)

Tus*_*ale 5

Materialize函数需要Jquery Elements.
getElementById() - 给我们DOM对象.

//You can either convert this Dom object to Jquery

var modal = document.getElementById('modal1');
var jquerymodal = $(modal);  //convert to jQuery Element
jquerymodal.openModal();


//Or just use Jquery Element like

$('#modal1').openModal();
Run Code Online (Sandbox Code Playgroud)