<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>test 1</title>
<script>
function changePicture( )
{
var x =Math.floor((Math.random()*3)+1);
var pic1 = document.getElementById("pic1");
var text1 = document.getElementById("text1");
if(x==1)
{
pic1.src ="
//pic1.width="240";
//pic1.height: "160" ;
}
else if(x==2)
{
pic1.src ="
//pic1.width="320";
//pic1.height: "195" ;
}
else
{
pic1.src ="
//pic1.width="500";
//pic1.height: "343" ;
}
text1.innerHTML += x+" " ;
}
</script>
</head>
<body>
<h2> Random picture </h2>
<img id = "pic1">
<br>
<button onclick ="changePicture( )"> click to random choose a picture
</button>
<p id = "text1"> </p>
</body>
</html>
練習的code