新手問題 (改了點內文)
<script type="text/javascript">
//事件三 隨機圖片產生
var a;
function myFunction() {
// 亂數
random = Math.floor(Math.random() * 500)
//新增圖片
var img = new Image();
img.src = "4.jpg";
a = img.className = "op2";
img.style.width = "50px";
img.style.height = "50px";
// 抓的到className alert(img.className);
alert(a);
//圖片出現的位置
document.body.appendChild(img);
img.style.position = "absolute";
img.style.top = 8 + "px";
img.style.left = random + "px";
}
setInterval("myFunction()", 1000);
alert(a);
</script>
我var a定義在廣域
但為何只能alert function內的
外面的抓不到值