如何修复在IE8兼容模式下运行但由于IE9及更高版本中的SCRIPT5007错误而失败的时间显示javascript

我是JavaScript的新手,并试图将旧的应用程序从IE 11(以IE8兼容模式运行)移至Chrome / Firefox / Edge,并遇到此错误-“ SCRIPT5007:无法设置属性'innerHTML'开头为“ timeElement.innerHTML =“的语句的未定义或null引用”。在IE9兼容模式和更高版本中,会发生相同的错误。

我已经做了很多研究,但是请保持干劲。有人可以帮忙吗?您的智慧将不胜感激!

这是时间显示脚本-

<SCRIPT type=text/javascript>
function DisplayTime(){
if (!document.all && !document.getElementById)
return
timeElement=document.getElementById? document.getElementById("curTime"):   document.all.tick2
var CurrentDate=new Date()
var hours=CurrentDate.getHours()
var minutes=CurrentDate.getMinutes()
var seconds=CurrentDate.getSeconds()
var DayNight="PM"
if (hours<12) DayNight="AM";
if (hours>12) hours=hours-12;
if (hours==0) hours=12;
if (minutes<=9) minutes="0"+minutes;
if (seconds<=9) seconds="0"+seconds;
var currentTime=hours+":"+minutes+":"+seconds+" "+DayNight;
timeElement.innerHTML="<font style='font-family:verdana,arial,tahoma;font-size:12px;color:#E25984; font-weight:bold;'>"+currentTime+"</b>"
setTimeout("DisplayTime()",1000)
}
window.onload=DisplayTime
</SCRIPT>
aazhenzhen 回答:如何修复在IE8兼容模式下运行但由于IE9及更高版本中的SCRIPT5007错误而失败的时间显示javascript

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3141366.html

大家都在问