Php 使用JQuery从动态按钮获取ID
我有从数据库获取值的php文件。 我无法从结果中获取id按钮。 我做错了吗 这是我的密码Php 使用JQuery从动态按钮获取ID,php,jquery,html,Php,Jquery,Html,我有从数据库获取值的php文件。 我无法从结果中获取id按钮。 我做错了吗 这是我的密码 <!DOCTYPE HTML> <html> <head> <link rel="stylesheet" href="css/bootstrap.min.css"> <script>src="jquery-3.3.1.js"</script> </head> <body> <div
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script>src="jquery-3.3.1.js"</script>
</head>
<body>
<div class="container">
<?php
include("koneksi.php");
$sql = "SELECT * FROM data_cv";
$result = $conn->query($sql);
?>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Nama</th>
<th>Nomor Identitas</th>
<th>Tempat Lahir</th>
<th>Tanggal Lahir</th>
<th>Jenis SIM</th>
<th>Masa SIM</th>
<th>Nomor SKCK</th>
<th>Pendidikan</th>
<th>Nomor Telepon (Handphone)</th>
<th>Keterangan</th>
<th>Terima Berkas</th>
<th>Tindakan</th>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_array($result)) {
echo '
<tr>
<td>'.$row["nama"].'</td>
<td>'.$row["id_ktp"].'</td>
<td>'.$row["tempat_lahir"].'</td>
<td>'.$row["tanggal_lahir"].'</td>
<td>'.$row["jenis_sim"].'</td>
<td>'.$row["masa_sim"].'</td>
<td>'.$row["no_skck"].'</td>
<td>'.$row["pendidikan"].'</td>
<td>'.$row["no_telp"].'</td>
<td>'.$row["keterangan"].'</td>
<td>'.$row["terima_berkas"].'</td>
<td><button id= "'.$row['id_ktp'].'" value="Accept"">Panggil</button></td>
</tr>
';
}
$conn->close();
?>
<script>
$("button").click(function() {
alert(this.id);
});
</table>
</div>
</div>
</body>
</html>
src=“jquery-3.3.1.js”
纳米
识别号
坦帕特拉希尔
唐加拉希尔
詹尼斯·辛
马萨辛
诺莫·斯卡克
潘迪迪坎
Nomor Telepon(手提电话)
凯特兰根
泰里玛·贝尔卡斯
廷达坎
$(“按钮”)。单击(函数(){
警报(this.id);
});
我的php文件结果如下
我想当我点击这个按钮时,我会根据php值从他们的id中得到警报。
请给我一些建议。不要使用
id
而是使用属性,然后使用类来定位按钮,例如:
然后在jQuery中,您可以使用数据api获取值
<script>
$(".valueButton").click(function() {
alert($(this).data('id'));
});
</script>
$(“.valueButton”)。单击(函数(){
警报($(this.data('id'));
});
我忽略了以下几点:
- 脚本标记错误
src=“jquery-3.3.1.js”
- 缺少
- 小心使用auto的“”,有些编辑器只是在你打字时加进去,让你保持警觉
src=“jquery-3.3.1.js”
。您确定控制台中没有jquery错误吗?您的
中的value=“Accept”
也有一个尾随“
@obsidiange我已将其替换为