【问题标题】:Javascript countdown does not show in Opera miniJavascript 倒计时不显示在 Opera mini 中
【发布时间】:2014-04-26 08:08:01
【问题描述】:

所以我有这个倒计时脚本,它几乎可以在每个浏览器中正常工作,但在 Opera mini 中却不行。它显示一个空白区域。 这是我的代码:

timer={
times:[],
init:false,
callback:function() { window.location.reload(); },
new:function(time)
{
    timer.times[timer.times.length]=time;
    document.write("<span id='timer_"+(timer.times.length-1)+"'>"+timer.format(time)+"</span>");
    timer.start();
},
format:function(time)
{
    days=Math.floor(time/(60*60*24));
    hours=Math.floor(time%(60*60*24)/(60*60));
    mins=Math.floor(time%(60*60)/60);
    secs=Math.floor(time%60);
    return (mins<10?"0":"")+mins+":"+(secs<10?"0":"")+secs+"";
},
ticker:function()
{
    for(var i=0; i<timer.times.length; i++)
    {
        if(timer.times[i] == 0) { timer.callback(); break; }
        document.getElementById("timer_"+i).innerHTML=timer.format(timer.times[i]);
        timer.times[i]--;
    }
},
start:function()
{
    if(!timer.init)
    {
        timer.init=true;
        setInterval(timer.ticker, 1000);
    }
}
}

代码有问题吗?

感谢您的帮助。

【问题讨论】:

  • 警告旁注:使用new(或任何其他保留字)作为文字属性名称在某些旧浏览器(例如IE8)中不起作用.它曾经是无效的语法 (ES3),仅在 ES5 中有效。例如,var obj = {new: "test"}; 将在 IE8 中失败,console.log(obj.new); 也将失败,但是您可以使用字符串文字形式和括号表示法:var obj = {"new": "test"};console.log(obj["new"]); 示例:Fails - Works。跨度>

标签: javascript timer countdown opera-mini


【解决方案1】:

只需在opera mini 控制台中检查您的代码是否有错误。在opera mini 中打开您的页面并在地址栏中写下:

server:console?post=http://path_to_your_page

另外,Opera Mini 有 javascript 计时器限制 - 它会在 2-5 秒后停止任何计时器(取决于 Opera Mini 版本)。我的 Android 计时器在 5 秒后停止 (fiddle)。

【讨论】:

    【解决方案2】:

    operamini 中定时器的工作方式不同,请阅读https://dev.opera.com/articles/opera-mini-content-authoring-guidelines/

    从上面的链接复制, 使用 setTimeout() 和 setInterval() 注册的代码可能会在页面发送之前运行,但不太可能因为脚本暂停而被多次调用

    【讨论】:

      猜你喜欢
      • 2013-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-28
      • 2012-04-28
      • 1970-01-01
      • 2018-10-31
      • 1970-01-01
      相关资源
      最近更新 更多