新手问题 (改了点内文)
<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内的
外面的抓不到值