我对 javascript 比较陌生,因此,当我的页面加载不起作用时,我的代码会显示随机图像。我查看了一些示例来尝试解决问题,但经过几个小时的搜索后,我准备按下帮助按钮。我已经为我的页面包含了 HTML 和脚本。此外,我还评论了我试图操纵的 IMG 标签。
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome in.</title>
<link href="home.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="slides.js"></script>
<script>
//This is where I am attempting to set an random image to load.
function()
{
//Array of quotes
var randomImages= new Array ("Images/quote1.png", "Images/quote2.png","Images/quote3.png", "Images/quote4.png", "Images/quote5.png","Images/quote6.png","Images/quote7.png","Images/quote8.png");
//Random number to select an image. Use 8, not 7, since javascript arrays are 0 based
//Math.floor will take us from a floating point number to an integer base
var randomNumber = Math.floor(7*Math.random());
//Display that image
document.getElementById('quoter').setAttribute('src',randomImages[randomNumber]);
}
</script>
</head>
<body onLoad="function()">
<a href="aboutme.html" id="aboutMe"><img src="Images/aboutme.png" alt="aboutme"/></a>
<a href="aboutme.html" id="contact"><img src="Images/contact.png" alt="aboutme"/></a>
<a href="aboutme.html" id="blog"><img src="Images/blog.png" alt="aboutme"/></a>
<a href="aboutme.html" id="wife"><img src="Images/mywife.png" alt="aboutme"/></a>
<div id="mid">
</div>
<div id="slideshow">
<div>
<img src="Images/dummypic.png" alt="me">
</div>
<div>
<img src="Images/dummypic2.png" alt="me">
</div>
<div>
<img src="Images/dummypic3.png" alt="me">
</div>
</div>
<div>
<img id="quoter" src="" alt="quotes"> <!--This is what I am trying to make random when the page loads-->
</div>
</body>
</html>