[英]Error with embedding moment.js
I am having difficulties including moment.js in my browser code. 我在浏览器代码中包含moment.js时遇到了困难。 This is my first time using it and teaching myself to use a library, so any help is appreciated.
这是我第一次使用它,并且自学使用图书馆,因此,我们非常感谢您的帮助。 I have a CDN for moment in my html page:
我的html页面上暂时有CDN:
<!-- jQuery cdn -->
<script src="http://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<!-- moment.js cdn -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/locale/af.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="script.js"></script>
<script type="text/javascript">
var momentTest = moment();
console.log(momentTest); // this is not logging
</script>
Also in my script.js file, I have tried calling it another way with format() like I saw in the docs: 同样在我的script.js文件中,我尝试用format()另一种方式调用它,就像我在文档中看到的那样:
var now = moment().format();
console.log(now); //this is not logging either
But I keep getting a console error - Uncaught ReferenceError: moment is not defined. 但是我一直收到控制台错误-Uncaught ReferenceError:时刻未定义。 Can anyone help with this?
有人能帮忙吗? I saw this article already but it didn't help me (total beginner with moment): How to use Moment.js?
我已经看过这篇文章,但对我没有帮助( 总的来说,对于初学者而言): 如何使用Moment.js?
This line does not load moment.js, but loads the af
(Afrikaans) locale for moment.js. 该行不会加载moment.js,但会加载moment.js的
af
(南非语)语言环境。
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/locale/af.js"></script>
To load moment.js, you'd want to load the moment.js
file instead: 要加载moment.js,您需要改为加载
moment.js
文件:
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script>
Try this: 尝试这个:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script> <script src="script.js"></script> <script type="text/javascript"> var momentTest = moment(); console.log(momentTest); // this is not logging </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.