我正在尝试在我的代码中使用easyPaginate.js插件(https://st3ph.github.io/jquery.easyPaginate/):

index.jsp

<script type="text/javascript" src="./js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="./js/myJs.js"></script>
<script type="text/javascript" src="./js/jquery.easyPaginate.js"></script>
...
<div id="easyPaginate">
    <img src="img/demo/surf1.jpg" />
    <img src="img/demo/surf2.jpg" />
</div>


myJs.js:

$('#easyPaginate').easyPaginate({
    paginateElement: 'img',
    elementsPerPage: 3,
    effect: 'climb'
});


但我收到以下错误:


  未捕获的TypeError:$(...)。easyPaginate不是函数
      在myJs.js:20

最佳答案

您应该按以下顺序声明脚本:

<script type="text/javascript" src="./js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="./js/jquery.easyPaginate.js"></script>
<script type="text/javascript" src="./js/myJs.js"></script>


如错误所示,在easyPaginate脚本中找不到myJs方法。

关于javascript - Javascript:“不是函数”错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46503889/

10-11 02:33