<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.content {
width: 400px;
margin: 50px auto;
font-size: 24px;
}
img {
width: 200px;
height: 200px;
}
</style>
</head>
<body>
<div class="content">
本次选择的名字是:<span id="name"></span>
<img src="" alt="" id="zp">
<input type="button" value="选择名字" onclick="selName();">
</div>
</body>
</html>
<script>
function selName() {
var arr = new Array(["1", "./随机照片/1.jpg"],
["2", "./随机照片/2.jpg"],
["3", "./随机照片/3.jpg"],
["4", "./随机照片/4.jpg"],
["5", "./随机照片/5.jpg"],
["6", "./随机照片/6.jpg"],
["7", "./随机照片/7.jpg"],
["8", "./随机照片/8.jpg"],
["9", "./随机照片/9.jpg"],
["10", "./随机照片/10.jpg"],
["11", "./随机照片/11.jpg"],
["12", "./随机照片/12.jpg"]);
var a = Math.ceil(Math.random() * (11 - 0) + 0) - 1;
document.getElementById("name").innerHTML = arr[a][0];
document.getElementById("zp").src = arr[a][1];
}
</script>
JS随机点名可加照片
最新推荐文章于 2024-09-02 17:34:07 发布