这是一个简单的设备管理网页的HTML代码示例,包含基本功能(添加/删除/搜索设备),采用响应式设计:
```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>简易设备管理系统</title>
<style>
body {
font-family: 'Arial', sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f5f5f5;
}
.container {
max-width: 1000px;
margin: 0 auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
}
.control-panel {
display: flex;
gap: 10px;
margin-bottom: 20px;
flex-wrap: wrap;
}
input, select, button {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
transition: background 0.3s;
}
button:hover {
background-color: #45a049;
}
.delete-btn {
background-color: #f44336;
}
.delete-btn:hover {
background-color: #d32f2f;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
tr:hover {
background-color: #f5f5f5;
}
@media (max-width: 600px) {
.control-panel {
flex-direction: column;
}
}
</style>
</head>
<body>
<div class="container">
<h1>设备管理系统</h1>
<div class="control-panel">
<input type="text" id="deviceName" placeholder="设备名称" required>
<select id="deviceType">
<option value="电脑">电脑</option>
<option value="打印机">打印机</option>
<option value="网络设备">网络设备</option>
<option value="其他">其他</option>
</select>
<input type="text" id="deviceId" placeholder="设备编号">
<button onclick="addDevice()">添加设备</button>
<input type="text" id="searchInput" placeholder="搜索设备...">
<button onclick="searchDevice()">搜索</button>
</div>
<table id="deviceTable">
<thead>
<tr>
<th>设备名称</th>
<th>类型</th>
<th>编号</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<!-- 示例数据 -->
<tr>
<td>联想ThinkPad</td>
<td>电脑</td>
<td>IT-001</td>
<td><button class="delete-btn" onclick="deleteDevice(this)">删除</button></td>
</tr>
<tr>
<td>HP打印机</td>
<td>打印机</td>
<td>PRT-002</td>
<td><button class="delete-btn" onclick="deleteDevice(this)">删除</button></td>
</tr>
</tbody>
</table>
</div>
<script>
// 添加设备
function addDevice() {
const name = document.getElementById('deviceName').value;
const type = document.getElementById('deviceType').value;
const id = document.getElementById('deviceId').value;
if (!name) {
alert('请填写设备名称');
return;
}
const table = document.getElementById('deviceTable').getElementsByTagName('tbody')[0];
const newRow = table.insertRow();
newRow.innerHTML = `
<td>${name}</td>
<td>${type}</td>
<td>${id || '未填写'}</