簡體   English   中英

如何使用Javascript更新Firefox中的DIV內容?

[英]How to update DIV content in Firefox using Javascript?

我在javascript中有以下代碼可以顯示div中的時間並進行更新:

  if (!document.all)
    return

  var Digital=new Date()
  var hours=Digital.getHours()
  var minutes=Digital.getMinutes()
  var seconds=Digital.getSeconds()
  var dn="AM" 

  if (hours>12){
   dn="PM"
   hours=hours-12
  }

  if (hours==0)
   hours=12

  if (minutes<=9)
   minutes="0"+minutes

  if (seconds<=9)
   seconds="0"+seconds
   var ctime=hours+":"+minutes+":"+seconds
   $("#c").text(ctime);

   setTimeout("show2()",1000)
}

window.onload=show2

我有這個div:

<div id=""c></div>

在IE中,一切正常,但是當我在Firefox中嘗試時,它不起作用。

我也嘗試使用

c.innerHTML=ctime

而且不起作用。

在IE和Firefox上執行此操作的正確方法是什么?

謝謝

這是第一行

if (!document.all)
    return

因為.all屬性僅存在於Explorer和Opera中。

您正在阻止其他瀏覽器繼續執行代碼

嘗試<div id="c"></div>document.getElementById('c').innerHTML = ctime;

並擺脫if (!document.all) return

去掉

  if (!document.all)
    return

因為document.all是僅限IE的擴展,並且FireFox不支持它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM