A-A+
Date.parse Firefox返回Nan的错误
利用 firefox 对 ecshop 进行兼职测试时,却意外发现了一个问题,就是对 firefox 对于时间,比如 2015-07-01,这样的时间格式不感冒,直接返回 Nan 的错误,夏日博客最终的解决方法是直接将符号“-”替换成了“/”,问题解决解决,实例代码如下:
- <script type=”text/javascript”>
- <!–
- var inputDate=”2015-07-01 15:55:00″;inputDate=inputDate.replace(“-”, “/”).replace(“-”, “/”);var nowDate=new Date();//alert(Date.parse(inputDate))//alert(Date.parse(nowDate))if(Date.parse(inputDate)<Date.parse(nowDate)){alert(“对不起,输入时间不能晚于当前时间!”);}
- // –>
- </script>
用.replace(/\-/g, ‘/’)一次就OK,不用两次REPLACE。
博主心还是比较细
不可以用字符实体吗..
对我的感觉是:专业动作,请勿模仿。