<!DOCTYPE html>
<html lang="en" οnclick="show()" >
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
function show(){
document.body.bgColor="black";
var img=document.createElement('img');
img.setAttribute('src','xingxing.gif');
var width=GetRandom(50,200);
var x=event.clientX-img.width/2;
var y=event.clientY-img.width/2;
img.setAttribute("style","position:absolute;left:"+x+"px;top:"+y+"px;");//修改style属性
img.setAttribute("width",width);
img.setAttribute("height",width);
document.body.appendChild(img);
function GetRandom(min,max){
return Math.floor((Math.random()*(max-min)+min));
}
}
show();
</script>
</body>
</html>
<html lang="en" οnclick="show()" >
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
function show(){
document.body.bgColor="black";
var img=document.createElement('img');
img.setAttribute('src','xingxing.gif');
var width=GetRandom(50,200);
var x=event.clientX-img.width/2;
var y=event.clientY-img.width/2;
img.setAttribute("style","position:absolute;left:"+x+"px;top:"+y+"px;");//修改style属性
img.setAttribute("width",width);
img.setAttribute("height",width);
document.body.appendChild(img);
function GetRandom(min,max){
return Math.floor((Math.random()*(max-min)+min));
}
}
show();
</script>
</body>
</html>