我在JS中进行了一些计算之后得到的是nan [英] I am getting as nan after some calculation in JS

查看:849
本文介绍了我在JS中进行了一些计算之后得到的是nan的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期的div,我在jquery函数中获取此值,
将它分配给一个函数,但它给了我NaN警报。

< div id =start_date>
22 10,2018
< / div>

var date = $('#start_date')。text();
var dates =4 15,2018;
//从div传递日期
var countDownDate = new Date(date + '12:00:00')。getTime();
alert(countDownDate); //提醒NaN





我的尝试:



我已经尝试解决这个问题,但我已经尝试了

这里是小提琴

编辑小提琴 - JSFiddle [ ^ ]

解决方案

('#start_date')。text();
var dates =4 15,2018;
//从div传递日期
var countDownDate = new Date(date + '12:00:00')。getTime();
alert(countDownDate); //提醒NaN





我的尝试:



我已经尝试解决这个问题,但我已经尝试了

这里是小提琴

编辑小提琴 - JSFiddle [ ^ ]


您的日期字符串不是有效日期类型,请参阅 JavaScript日期对象 [ ^ ]

I have div with the one date, i am fetching this value in jquery function and
 assigning it to a function, but it gives me NaN alert.

<div id="start_date">
22 10, 2018
</div>

var date=$('#start_date').text();
var dates="4 15, 2018";
//passing date from the div
var countDownDate = new Date(date+ '12:00:00').getTime();
alert(countDownDate);//alert NaN



What I have tried:

I have tried resolving this problem but i coudnt
here is the fiddle
Edit fiddle - JSFiddle[^]

解决方案

('#start_date').text(); var dates="4 15, 2018"; //passing date from the div var countDownDate = new Date(date+ '12:00:00').getTime(); alert(countDownDate);//alert NaN



What I have tried:

I have tried resolving this problem but i coudnt
here is the fiddle
Edit fiddle - JSFiddle[^]


Your date strings are not valid date types, see JavaScript Date Objects[^].


这篇关于我在JS中进行了一些计算之后得到的是nan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆