當前處於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