【问题标题】:moment() function works in html but not in separate javascript filemoment() 函数在 html 中有效,但在单独的 javascript 文件中无效
【发布时间】:2014-06-07 12:31:12
【问题描述】:

我的页面中包含了 moment.min.js

<script src="js/jquery.js"></script>
<script src="js/modernizr.js"></script>
<script src="js/moment.min.js"></script>
<script src="js/fatcalc.js"></script>

我可以打电话

<script>document.write(moment());</script>

它在我的页面上显示日期很好。

但是,当我从 fatcalc.js 中调用它时

var date = moment();

我得到错误:

“时刻”未定义。

为什么我的html页面可以看到,而fatcalc.js文件却看不到?

【问题讨论】:

    标签: javascript html momentjs


    【解决方案1】:

    好吧,我想通了。似乎是 Jshint 的一些问题,我不明白,但将其添加到我的脚本顶部修复了它。

    /*global moment:true */
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      • 2011-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多