开发者

How to update DIV content in Firefox using Javascript?

开发者 https://www.devze.com 2023-01-22 08:48 出处:网络
I have this code in javascript to show time in div and update it: if (!document.all) return var Digital=new Date()

I have this code in javascript to show time in div and update it:

  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);

   setTim开发者_开发技巧eout("show2()",1000)
}

window.onload=show2

and I have this div :

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

in IE every thing is ok but when I try it in Firefox, it's not working.

I also tried to use

c.innerHTML=ctime

and it's not working.

What is the right way to do it on both IE and Firefox?

Thanks


it's the first line

if (!document.all)
    return

since .all property exists on Explorer and Opera only.

You are preventing other browser to continue code execution


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

and get rid of if (!document.all) return


Remove

  if (!document.all)
    return

since document.all is an IE only extension, and FireFox doesn't support it

0

精彩评论

暂无评论...
验证码 换一张
取 消