javascript - Access Data on click event from table
问题描述
i have table "login" and listing the data from mysql using php into table in html.
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">Sl.NO</th>
<th scope="col">Name</th>
<th scope="col">Username</th>
<th scope="col">Mobile</th>
<th scope="col">Join Date</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
if($req_result->num_rows > 0)
{
while($req_row = $req_result->fetch_assoc()) {
$i+=1;
$reqmail = $req_row['username'];
$reqmobile = $req_row['id'];
$reqname = $req_row['name'];
$join_date = $req_row['join_date'];
?>
<tr>
<th scope="row"><?php echo $i ;?></th>
<td><?php echo $reqname ;?></td>
<td><?php echo $reqmail ;?></td>
<td><?php echo $reqmobile ;?></td>
<td><?php echo $join_date ; ?></td>
<td><button type="submit" value="'.$reqmobile.'" class="btn btn-primary" data-toggle="modal" data-target="#confirm">Approve</button></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
i want to acccess that button value on click, and process another queries.the tbale "login" has multiple datas. how can i do it?
解决方案
尝试使用这个。如果出现问题,请告诉我。干杯
//catch html button with js assigned to variable button
let button = document.querySelector('.btn btn-primary');
//listen for the click
button.addEventListener('click', function(){
button.value;
});
// console log the the value of button
console.log(button);
推荐阅读
- selenium - 创建一个测试 Web 应用程序重放以测试并预热服务器
- docker - Docker错误:无法启动服务...:找不到网络7808732465bd529e6f20e4071115218b2826f198f8cb10c3899de527c3b637e6
- javascript - 使用 querySelectorAll 查找与逗号分隔的属性的匹配项
- windows - 是否可以使用登录的 Windows 用户凭据对 Web API 进行身份验证?
- python - 谷歌 colab TPU 和在训练时从光盘读取
- c++ - 什么是 consteval?
- pagespeed - Google PageSpeed Insights 一切错误
- cassandra - 创建键空间时 Cassandra 中的复制因子
- flowtype - 使用 immutablejs 记录并在其中调用更新时无法解决流注释错误
- algorithm - 带有 if 语句的递归函数