javascript - 如何使用 php 和 html 使表格条目可点击?
问题描述
我正在尝试使此代码中的下表可单击。基本上,当用户单击它时,行元素将被发送到一个 PHP 文件中,该文件包含一个表单以对单击的用户进行一些更新。该表单将使用上一个表单击条目中的数据进行预填充,因此必须对用户的特定选择进行一些更新。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Table V04</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->
<link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/animate/animate.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/perfect-scrollbar/perfect-scrollbar.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="css/util.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<!--===============================================================================================-->
</head>
<body>
<div class="centerThis">
<a class="thisButton" href="createUser.html" >Create New User</a>
</div>
<div class="limiter">
<div class="container-table100">
<div class="wrap-table100">
<div class="table100 ver1 m-b-110">
<div class="table100-head">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr class="row100 head">
<th class="cell100 column1">User Firstname</th>
<th class="cell100 column1">User Lastname</th>
<th class="cell100 column1">User Email</th>
<th class="cell100 column1">User Type</th>
</tr>
</thead>
</table>
</div>
<div class="table100-body js-pscroll ps ps--active-y">
<table>
<tbody>
<?php
include '../connection.php';
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql2 = "SELECT user_Firstname,user_Lastname,user_Email,user_Type FROM User ORDER BY user_Firstname ";
$resultForm2=mysqli_query($conn,$sql2);
while ($row = mysqli_fetch_array($resultForm2)) {
echo "<tr class='row100 body'>
<td class='cell100 column1'>" . $row[0] . "</td>
<td class='cell100 column2'>" . $row[1] . "</td>
<td class='cell100 column3'>" . $row[2] . "</td>
<td class='cell100 column4'>" . $row[3] . "</td>
</tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!--===============================================================================================-->
<script src="vendor/jquery/jquery-3.2.1.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/bootstrap/js/popper.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/select2/select2.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/perfect-scrollbar/perfect-scrollbar.min.js"></script>
<script>
$('.js-pscroll').each(function(){
var ps = new PerfectScrollbar(this);
$(window).on('resize', function(){
ps.update();
})
});
</script>
<!--===============================================================================================-->
<script src="js/main.js"></script>
</body>
</html>
解决方案
如果您想在单击表格行时重定向页面,这将对您有所帮助。
$(document).ready(function () {
$('body').on('click', '.table tbody tr', function () {
window.location.href = 'redirect-link-here';
});
});
推荐阅读
- python - TypeError:视图函数没有返回有效的响应元组。元组的形式必须为 (body, status, headers), (body, status),
- excel - Excel vlookup为所有记录返回相同的值
- vba - VBA - 处理带有 utf8 字符的文件夹名称
- python - 使用美汤提取嵌套的 span/p/div 结构
- ruby - 在存在不同 ruby 版本的文件夹中使用全局 Ruby 脚本
- javascript - 使用 Cookie 保存每个用户的清单
- c# - Visual Studio c#:复制一个 tabPage 并保留控件名称
- azure - Azure DevOps Pipelines 停止运行
- java - 如何在 Java (JavaFX) 中使用另一个类的标签
- javascript - React styleguidist ReferenceError:未定义流程