<!DOCTYPE html>
<html>
<head>
	<title>随机图片</title>
	<meta charset="utf-8">
	<style type="text/css">
		img {
			width: 50%;
			height: auto;
			margin: 10px;
			border: 1px solid black;
			padding: 5px;
			box-shadow: 5px 5px 5px grey;
		}
		button {
			font-size: 20px;
			padding: 10px 20px;
			background-color: #4CAF50;
			color: white;
			border: none;
			border-radius: 5px;
			cursor: pointer;
		}
	</style>
</head>
<body>
	<div id="image-container"></div>
	<button onclick="randomImage()">随机图片</button>
<pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
	function randomImage() {
		var imageArray = [];
		for (var i = 1; i &lt;= 427; i++) {
			imageArray.push(i + &quot;.jpg&quot;);
		}
		var randomIndex = Math.floor(Math.random() * imageArray.length);
		var randomImage = imageArray[randomIndex];
		document.getElementById(&quot;image-container&quot;).innerHTML = &quot;&lt;img src='&quot; + randomImage + &quot;'&gt;&quot;;
	}
&lt;/script&gt;
</code></pre>
</body>
</html
我有一些jpg文件分别为1jpg2jpg427jpg请帮我写一个html网页该网页有一个按钮点击随机出现一张上述jpg照片中的一张

原文地址: https://www.cveoy.top/t/topic/cyWR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录