编写一个HTML具有修改按钮弹窗的表格
时间: 2024-03-22 21:42:15 浏览: 48
Layui 带多选框表格监听事件以及按钮自动点击写法实例
好的,以下是一个简单的示例代码,实现一个包含修改按钮弹窗的HTML表格:
```html
<!DOCTYPE html>
<html>
<head>
<title>修改按钮弹窗的表格</title>
<meta charset="UTF-8">
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
.btn {
background-color: #4CAF50;
color: white;
padding: 6px 12px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4);
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover, .close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<h2>修改按钮弹窗的表格</h2>
<table>
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr>
<td>张三</td>
<td>26</td>
<td>男</td>
<td>
<button class="btn" onclick="openModal()">修改</button>
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal()">×</span>
<h3>修改信息</h3>
<form>
<label>姓名:</label>
<input type="text" name="name" value="张三"><br><br>
<label>年龄:</label>
<input type="text" name="age" value="26"><br><br>
<label>性别:</label>
<input type="radio" name="gender" value="male" checked>男
<input type="radio" name="gender" value="female">女<br><br>
<input type="submit" value="提交">
</form>
</div>
</div>
</td>
</tr>
<tr>
<td>李四</td>
<td>30</td>
<td>女</td>
<td>
<button class="btn" onclick="openModal()">修改</button>
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal()">×</span>
<h3>修改信息</h3>
<form>
<label>姓名:</label>
<input type="text" name="name" value="李四"><br><br>
<label>年龄:</label>
<input type="text" name="age" value="30"><br><br>
<label>性别:</label>
<input type="radio" name="gender" value="male">男
<input type="radio" name="gender" value="female" checked>女<br><br>
<input type="submit" value="提交">
</form>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<script>
var modal = document.getElementById("myModal");
function openModal() {
modal.style.display = "block";
}
function closeModal() {
modal.style.display = "none";
}
</script>
</body>
</html>
```
注:该示例代码并不完整,仅供参考。如果您想要实现更复杂的功能,可以根据自己的需求进行修改。
阅读全文