当前处于Coursera作业的中间,但无法获得左侧div以显示图像。如何在id =“leftSide”内的div中显示图像?
有人可以请教我的代码有什么问题吗?谢谢!
<DOCTYPE! html>
<html>
<head>
<title>Matching Game - Smiling :)</title>
<style>
div, img {position: absolute;}
div {width: 500px; height: 500px;}
#rightSide {left: 500px; border-left: 1px solid black}
</style>
<script type="text/javascript">
var numberOfFace = 5;
var theLeftSide = document.getElementById('leftSide');
var top_random = (Math.random() * 400);
var left_random = (Math.random() * 400);
var count = 0
function generateFaces() {
var smiling_face = document.createElement("img");
document.getElementsByTagName("img").src="http://home.cse.ust.hk/~rossiter/mooc/matching_game/smile.png"
img.src = "http://home.cse.ust.hk/~rossiter/mooc/matching_game/smile.png";
smiling_face.style.top = Math.floor(top_random);
smiling_face.style.left = Math.floor(left_random);
while (count < numberOfFace) {
theLeftSide.appendChild(smiling_face);
count = count ++;
}
}
</script>
</head>
<body onload="generateFaces()">
<h1>Matching Game</h1>
<p>Click on the extra smiling face on the right!</p>
<div id="leftSide"></div>
<div id="rightSide"></div>
</body>
</html>
什么是'img'变量,似乎没有定义? – callback