gpt4 book ai didi

javascript - Uncaught ReferenceError : swapImage is not defines

转载 作者:行者123 更新时间:2023-11-30 17:25:38 25 4
gpt4 key购买 nike

我对此很陌生,但这是交易。

起初我遇到了麻烦,因为只有一个 javascript 元素会显示。我从 matt ellen 那里得到了一些帮助,我注意到我的代码中有两次 window.onload。我从函数中删除了它们并添加了一行我包含这两个函数的地方。

<head>

<link rel="shortcut icon" href="bavafavicon"/>
<title>Berlin Airlift Veterans Association: News</title>
<link rel="stylesheet" type="text/css" href="main.css">

</head>

<body id="news">
<div id="container">

<div id="left"></div>
<div id="leftblue"></div>
<div id="right"></div>
<div id="topyellow"></div>
<div id="topred"></div>

<div id="slider">
<script type="javascript">
var i = 0; var path = new Array();
path[0] = "1.jpg";
path[1] = "2.jpg";
path[2] = "3.jpg";
path[3] = "4.jpg";
path[4] = "5.jpg";
path[5] = "6.jpg";
function swapImage()
{
document.slide.src = path[i];
if(i < path.length - 1) i++;
else i = 0;
setTimeout("swapImage()",5500);
}
</script>
<img name="slide"/>
</div>

<ul id="head_nav">
<li><a href="index.htm" class="currentButton">NEWS</a></li>
<li><a href="aboutbava.htm" class="button">ABOUT BAVA</a></li>
<li><a href="history.htm" class="button">HISTORY</a></li>
<li><a href="biographies.htm" class="button">BIOGRAPHIES</a></li>
<li><a href="calendar.htm" class="button">CALENDAR</a></li>
<li><a href="contact.htm" class="button">CONTACT</a></li>
<li><a href="links.htm" class="button">LINKS</a></li>
<li><a href="donate.htm" class="button">DONATE</a></li>
</ul>

<div id="headlogo">
<img src="BAVA.png" alt="BAVA logo" width="150" height="150"/>
</div>
<div id="subscribe">Sign up for BAVA updates!<br>

<img src="emailBomb.png" alt="emailBomb" id="emailBomb" width="150" height="300"/>
<form action="demo_form.asp">
E-mail: <input type="email" name="userid">
<input type="submit" value="Submit"><br></form>

<script type="javascript">

function GetClock(){
tzOffset = +2;

d = new Date();
dx = d.toGMTString();
dx = dx.substr(0,dx.length -3);
d.setTime(Date.parse(dx))
d.setHours(d.getHours() + tzOffset);
nday = d.getDay();
nmonth = d.getMonth();
ndate = d.getDate();
nyear = d.getYear();
nhour = d.getHours();
nmin = d.getMinutes();
if(nyear<1000) nyear=nyear+1900;

if(nmin <= 9){nmin="0"+nmin}


document.getElementById('berlinClock').innerHTML=""+(nmonth+1)+"/"+ndate+"/"+nyear+" "+nhour+":"+nmin+"";
setTimeout("GetClock()", 1000);
}
</script> <script type="text/javascript" language="javascript">
window.onload = function() { swapImage(); GetClock(); };
</script>
<div id="berlinClock"></div>



</div>


</div>
<footer>
<div id="footer">
<p><i>15 N. College Ave, Newton, NC 28658 | (828) 466-3410</i></p>
</div>
</footer>

</body>

我不再使用外部 js。

最佳答案

您设置了两次 window.onload。它将是第二个,即 GetClock,它将运行,而不是第一个。

您需要添加一个函数调用,在声明两个函数后调用这两个函数,然后删除其他分配给 onload。

window.onload = function() { swapImage(); GetClock(); };

这是一个 fiddle来证明我的意思。

顺便说一句;您的第一个脚本标记中的语言属性不正确。它应该是 javascript 而不是 JavasScript/text

关于javascript - Uncaught ReferenceError : swapImage is not defines,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24343772/

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