<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>随机显示图片</title>
</head>
<script>
function randomShowPin(){
[color=green]//通过img标签的id即pic获取img标签的属性src,得到图片地址
//Math调用ceil方法为向上取整[/color]
[color=green]//图片放在images文件夹里,images和js_randomShowPic.htm在同一级目录[/color]
pic.src = "/images/"+Math.ceil((5*Math.random()))+".jpg"
}
</script>
<body>
<img id="pic" width="400" height="300">
<a href="javascript:randomShowPin()">随机显示图片</a>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>随机显示图片</title>
</head>
<script>
function randomShowPin(){
[color=green]//通过img标签的id即pic获取img标签的属性src,得到图片地址
//Math调用ceil方法为向上取整[/color]
[color=green]//图片放在images文件夹里,images和js_randomShowPic.htm在同一级目录[/color]
pic.src = "/images/"+Math.ceil((5*Math.random()))+".jpg"
}
</script>
<body>
<img id="pic" width="400" height="300">
<a href="javascript:randomShowPin()">随机显示图片</a>
</body>
</html>