在bootstrap模式下,要使表单在表格行的对应按钮被点击时获取电子邮件的输入,可以通过以下步骤实现:
下面是一个示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap Form Example</title>
<!-- 引入Bootstrap框架的CSS文件 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
</head>
<body>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>John Doe</td>
<td><input type="email" class="form-control" id="emailInput1"></td>
<td><button class="btn btn-primary" onclick="getEmail(1)">Get Email</button></td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jane Smith</td>
<td><input type="email" class="form-control" id="emailInput2"></td>
<td><button class="btn btn-primary" onclick="getEmail(2)">Get Email</button></td>
</tr>
<!-- 添加更多的表格行 -->
</tbody>
</table>
<!-- 引入Bootstrap框架的JS文件 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
function getEmail(row) {
// 获取对应行的输入框的值
var emailInput = document.getElementById("emailInput" + row);
var email = emailInput.value;
// 处理获取到的电子邮件,比如发送邮件等
console.log("Email: " + email);
}
</script>
</body>
</html>
上述示例代码中,每一行都包含一个输入框和一个按钮。当按钮被点击时,通过JavaScript的getEmail()
函数获取相应行的输入框中的电子邮件的值,并进行相应处理。
注意:以上示例中使用了Bootstrap 5版本的CDN链接,你也可以下载对应版本的Bootstrap文件并引入到项目中。此外,该示例只展示了如何获取输入框中的电子邮件,你可以根据实际需求进行相应的扩展和功能实现。
腾讯云相关产品和产品介绍链接地址,请参考腾讯云官方文档或咨询腾讯云官方客服以获取最新信息。
领取专属 10元无门槛券
手把手带您无忧上云