【发布时间】:2017-07-29 05:05:51
【问题描述】:
我有一个引导表,其中元素是从数据库加载的。 我有一个 js 函数可以从数据库中删除一个表行,所以我在表的每一行中添加了一个按钮。
<table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>id</th>
<th>client</th>
</tr>
</thead>
<tbody>
<?php
require("config.php");
// Create connection
$conn = new mysqli($host, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM users";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_row()) {
$user_id=$row[0];
$user_name=$row[1];
?>
<tr>
<!--here showing results in the table -->
<td><?php echo $user_id; ?></td>
<td ><?php echo $user_name; ?></td>
<td>
<input type="button" class="btn btn-danger btn-xs delete" value="Cancella sin id" onclick="deleteFunction()"/>
</td>
</tr>
</tbody>
</table>
如何将 id 或 user_name 传递给 deleteFucntion 以便像这样在 Javascipt 中使用它们:
function deleteFunction() {
var username = #MY_ROW_USERNAME;
....
}
【问题讨论】:
-
如果在循环时将按钮添加到每一行,则可以将 id 添加到按钮
onclick="functionDelete(id)"的onclick中
标签: javascript twitter-bootstrap html-table