简体   繁体   English

Javascript在Chrome上有效,但在IE或FF上无效

[英]Javascript works on Chrome, but no on IE or FF

I have a Javascript code on my page that counts time since the user logged on. 我的页面上有一个Javascript代码,该代码计算自用户登录以来的时间。
I'm using the script from here 我正在从这里使用脚本
The thing is the on Chrome, the script works perfectly, but on IE or FF it won't work. 问题是在Chrome上,脚本可以完美运行,但在IE或FF上则无法运行。
Is there anyway I can make it work on all 3 browsers? 无论如何,我可以使其在所有3种浏览器上都能正常工作吗?
Thank you! 谢谢!

在此处输入图片说明

My code: 我的代码:
Javascript: (the %%DATE%% is replaced by a string like: 2011-07-25 14:12:59 Javascript :(将%% DATE %%替换为以下字符串: 2011-07-25 14:12:59

<script type="text/javascript"> 
function parse_date(string) {  
    var date = new Date();  
    var parts = String(string).split(/[- :]/);  

    date.setFullYear(parts[0]);  
    date.setMonth(parts[1] - 1);  
    date.setDate(parts[2]);  
    date.setHours(parts[3]);  
    date.setMinutes(parts[4]);  
    date.setSeconds(parts[5]);  
    date.setMilliseconds(0);  

    return date;  
}  

//$(function () {
//  var austDay = new Date();
//  austDay = new Date("%%DATE%%");
//  austDay.setSeconds(austDay.getSeconds()+3);
//  $('#time_square').countdown({since: austDay, format: 'MS', compact: true});
//});

function set_time() {
    var austDay = new Date();
    austDay = new Date("%%DATE%%");
    austDay.setSeconds(austDay.getSeconds()+3);
    $('#time_square').countdown({since: austDay, format: 'MS', compact: true});
};

function validate()
{
  var retval = false;
  for (var i=0; i < document.form.r.length; i++)
  {
    if (document.form.r[i].checked)
    {
      retval = true;
    }
  }  

  return retval;
}

function set_interval() {
setInterval("set_time()",100);
}
</script>

HTML: HTML:

<body bgcolor="#000000" topmargin="0" onload="set_interval()">

<table width="166" border="0">
  <tr>
    <td width="45"><font color="#FFFFFF" size="5px">Time:</font></td>
    <td width="111"><div id="time_square"></div></td>
  </tr>
</table>

Avoid using setFullYear. 避免使用setFullYear。 though set/getYear is depricated, most of them gives errors. 尽管set / getYear被描述,但大多数都给出了错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM