【发布时间】:2016-02-27 00:25:27
【问题描述】:
您好,我有一个问题,即不显示我的 javascript,我有点困惑,因为它在 google chrome 中运行良好。我尝试了 f12 调试并启用了 javascript,但没有任何运气,因此非常感谢任何帮助。在 chrome 中,它显示正确的天数,而在 ie 中,它只显示 NaN。
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
function countup(yr,m,d){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy
var paststring=montharray[m-1]+" "+d+", "+yr
var difference=(Math.round((Date.parse(todaystring)-Date.parse(paststring))/(24*60*60*1000))*1)
difference+=" days"
document.write("<span style=\"color:#A4A4A4;font-size: 3em; \"> It\'s been "+difference+" since the last incident.<\/span>")
}
//enter the count up date using the format year/month/day
countup('<?php echo $date1; ?>')
【问题讨论】:
-
欢迎来到网络开发。
-
@Virtyaluk 提出了一个有效的问题:$date1 还返回了什么,哪个 IE?它在 Edge 中运行良好,除非您的值如评论建议的那样(如格式
'2016/02/25')返回 NAN days -
取一个已知的日期对象很奇怪......把它变成字符串,转身然后在那个字符串上使用 Date.parse()
-
好吧,我再说一遍,
<?php echo $date1; ?>究竟返回了什么? -
您好,很抱歉迟到了回复,因为我一直在工作,$date1 返回一个 mysql 日期,将是 2016/02/25,但我尝试将日期更改为不同的格式,但没有成功跨度>
标签: javascript google-chrome internet-explorer