gpt4 book ai didi

javascript 启动不当

转载 作者:行者123 更新时间:2023-11-28 15:13:40 24 4
gpt4 key购买 nike

作为我的作业,我必须为数据库首页准备一个 asp 网页。为了获得一些额外的分数,我们可以添加一个 javascript。我决定添加一个我在脚本教程中找到的时钟并对其进行了一些修改,但我的技能不足以正确放置它

我想将它放在我的 MasterPage 中,但如果我像这样添加它,整个页面只会消失剩下的时钟:

<div id="Zawartosc" onload="showTheTime();">
<%-- clock --%>
<script src="Script.js"></script>
</div>

这是时钟脚本:

function showTheTime() {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();

var ampm = "am";
var colon = '<IMG SRC="clock/colon.gif">';

if (hours < 10) hours = "0" + hours;
else hours = hours + '';

if (minutes < 10) minutes = "0" + minutes;
else minutes = minutes + '';

if (seconds < 10) seconds = "0" + seconds;
else seconds = seconds + '';

document.write('<IMG SRC="clock/' + hours.charAt(0) + '.gif">');
document.write('<IMG SRC="clock/' + hours.charAt(1) + '.gif">');
document.write(colon);
document.write('<IMG SRC="clock/' + minutes.charAt(0) + '.gif">');
document.write('<IMG SRC="clock/' + minutes.charAt(1) + '.gif">');
document.write(colon);
document.write('<IMG SRC="clock/' + seconds.charAt(0) + '.gif">');
document.write('<IMG SRC="clock/' + seconds.charAt(1) + '.gif">');
}
setTimeout("showTheTime()", 1000);
showTheTime();

您能否引导或帮助我更正代码并使时钟在我的页面上正确显示?

最佳答案

来自w3schools.com

The write() method is mostly used for testing: If it is used after an HTML document is fully loaded, it will delete all existing HTML.

关于javascript 启动不当,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35113461/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com