简体   繁体   English

JavaScript适用于IE和Edge,但不适用于Chrome和Firefox

[英]JavaScript working on IE and Edge but not working on Chrome and Firefox

This is working fine on IE and Edge but showing NaN:NaN in Chrome and Firefox. 在IE和Edge上运行正常,但在Chrome和Firefox中显示NaN:NaN。 Please provide reason and correct solution for it I am trying to show only one hour decreasing time. 请提供原因和正确的解决方案,我尝试仅减少一小时。

<!--HERE IS MY CODE-->
<!--THE CODE CREATIN ERROR-->
<html>
<head>
<script>
    endtime="31/12/2015";
    var myvar=setInterval(myfunc,1000);//function calling after every 1 second
    var d=new Date();
    d.setHours(14);
    d.setMinutes(00);


    k=00;
    j=01;
    function myfunc()
    {strong text
        d.setSeconds(k);
        k++;
        if(k==60)
        {
            d.setMinutes(j);
            k=00;
            j++;
        }
        var t = parseFloat(Date.parse(endtime) - Date.parse(d));
        var seconds = Math.floor( (t/1000) % 60 );
        var minutes = Math.floor( (t/1000/60) % 60 );
        var hours = Math.floor( (t/(1000*60*60)) % 24 );
        var days = Math.floor( t/(1000*60*60*24) );
        document.getElementById("div1").innerHTML=minutes.toString()+":"+seconds.toString();/*HERE IT IS SAYING NAN:NAN IN CHROME AND FIREFOX*/
    }
</script>
</head>
<body>
<p id="demo"></p>
<div id="div1"></div>
</body>
</html>

tried to solve a problem from a new approach and done it. 尝试通过新方法解决问题并做到了。

<html>
<head>
    <script>

            var t = parseFloat(3600000);

            var myvar=setInterval(myfunc,1000);

            function myfunc()
            {
            if(t>0)
            {
            var seconds = parseFloat(Math.floor( (t/1000) % 60 ).toString());
            var minutes = parseFloat(Math.floor( (t/1000/60) % 60 ).toString());
            var hours = Math.floor( (t/(1000*60*60)) % 24 );
            var days = Math.floor( t/(1000*60*60*24) );
            document.getElementById("div1").innerHTML=minutes+":"+seconds;

            t=t-1000;
            };}
    </script>
</head>
<body>
<p id="demo"></p>
<div id="div1"></div>   
</body>
</html>

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

相关问题 JavaScript 在 Firefox、Chrome 中不起作用 - 在 IE、Edge 中有效 - JavaScript not working in Firefox, Chrome - works in IE, Edge Chrome可在Chrome,Opera和Edge上使用Javascript,但在FireFox或IE 11上则无法使用 - Javascript working on Chrome & Opera & Edge, but not on FireFox or IE 11 Javascript在chrome中工作,而不是firefox或ie - Javascript working in chrome, not firefox or ie Javascript可在Firefox中运行,但不能在IE或Chrome中运行 - Javascript working in firefox but not IE or chrome Javascript 在 Edge 中不起作用,但在 Firefox、Chrome 中很好 - Javascript not working in edge, but fine in Firefox, Chrome Facebook JavaScript无法在IE上运行,但可以在Firefox和Chrome上运行 - Facebook JavaScript not working on IE, but working on Firefox and Chrome jQuery 不能在 IE11 上运行,但可以在 Chrome、Firefox 和 Edge 上运行? - jQuery not working on IE11 but working on Chrome, Firefox and Edge? promise function 在 Chrome 和 Firefox 中工作,但不在 IE Edge 和 IE11 中 - promise function working in Chrome and Firefox but not in IE Edge and IE11 页面可在Edge,Chrome和Firefox中运行,但不能在IE11中运行 - Page working in Edge, Chrome and Firefox but not IE11 javascript在chrome / opera / IE中不起作用,但是firefox非常好! - javascript not working in chrome/opera/IE but firefox is excellent!
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM