<!DOCTYPE html>
<html>
<head>
	<title>I Spy Game</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<style>
		body {
			font-family: Arial, sans-serif;
			background-color: #f2f2f2;
		}
		h1 {
			text-align: center;
			color: #333;
		}
		.container {
			max-width: 800px;
			margin: 0 auto;
			padding: 20px;
			background-color: #fff;
			border-radius: 5px;
			box-shadow: 0 0 10px rgba(0,0,0,0.3);
		}
		.table {
			border-collapse: collapse;
			margin: 20px 0;
		}
		.table th, .table td {
			padding: 10px;
			border: 1px solid #ddd;
			text-align: center;
		}
		.table th {
			background-color: #f2f2f2;
			color: #333;
			font-weight: bold;
		}
		.table td {
			font-size: 20px;
			font-weight: bold;
			color: #999;
			cursor: pointer;
			transition: all 0.3s ease-in-out;
		}
		.table td:hover {
			background-color: #eee;
		}
		.table td.selected {
			background-color: #ffc107;
			color: #fff;
		}
		.message {
			font-size: 24px;
			font-weight: bold;
			color: #333;
			text-align: center;
			margin-top: 50px;
			display: none;
		}
		.message.won {
			color: green;
		}
		.message.lost {
			color: red;
		}
		.btn {
			display: inline-block;
			padding: 10px 20px;
			background-color: #4CAF50;
			color: #fff;
			text-decoration: none;
			border-radius: 5px;
			box-shadow: 0 0 5px rgba(0,0,0,0.3);
			cursor: pointer;
			transition: all 0.3s ease-in-out;
		}
		.btn:hover {
			background-color: #333;
			color: #fff;
		}
	</style>
</head>
<body>
	<h1>I Spy Game</h1>
	<div class="container">
		<table class="table">
			<tr>
				<th>Item</th>
				<th>Found</th>
			</tr>
			<tr>
				<td>Key</td>
				<td class="item"></td>
			</tr>
			<tr>
				<td>Pen</td>
				<td class="item"></td>
			</tr>
			<tr>
				<td>Glasses</td>
				<td class="item"></td>
			</tr>
			<tr>
				<td>Phone</td>
				<td class="item"></td>
			</tr>
			<tr>
				<td>Watch</td>
				<td class="item"></td>
			</tr>
			<tr>
				<td>Wallet</td>
				<td class="item"></td>
			</tr>
		</table>
		<div class="message"></div>
		<button class="btn" onclick="startGame()">Start Game</button>
	</div>
	<script>
		var items = ['key', 'pen', 'glasses', 'phone', 'watch', 'wallet'];
		var found = 0;
		var total = items.length;
<pre><code>	function startGame() {
		var cells = document.querySelectorAll('.item');
		cells.forEach(function(cell) {
			cell.textContent = 'No';
			cell.classList.remove('selected');
			cell.onclick = function() {
				if (!cell.classList.contains('selected')) {
					cell.textContent = 'Yes';
					cell.classList.add('selected');
					found++;
					checkGame();
				}
			}
		});
		var btn = document.querySelector('.btn');
		btn.style.display = 'none';
	}

	function checkGame() {
		if (found == total) {
			var msg = document.querySelector('.message');
			msg.textContent = 'Congratulations! You found all the items.';
			msg.classList.add('won');
			msg.style.display = 'block';
		}
	}
&lt;/script&gt;
</code></pre>
</body>
</html>
Make me html sample code I spy

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

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