我有php文件,可从数据库中获取价值.
我很难从结果中获得一个动态的id按钮.
我做错了吗?
这是我的代码
include("koneksi.php");
$sql = "SELECT * FROM data_cv";
$result = $conn->query($sql);
?>
NamaNomor IdentitasTempat LahirTanggal LahirJenis SIMMasa SIMNomor SKCKPendidikanNomor Telepon (Handphone)KeteranganTerima BerkasTindakan
while ($row = mysqli_fetch_array($result)) {
echo '
'.$row["nama"].''.$row["id_ktp"].''.$row["tempat_lahir"].''.$row["tanggal_lahir"].''.$row["jenis_sim"].''.$row["masa_sim"].''.$row["no_skck"].''.$row["pendidikan"].''.$row["no_telp"].''.$row["keterangan"].''.$row["terima_berkas"].'Panggil';
}
$conn->close();
?>
$("button").click(function() {
alert(this.id);
});
我的PHP文件结果是这样
我想要当我单击按钮时,我从基于php值的id中获得警报.
请给我建议.
解决方法:
不要使用id而是使用data-属性,然后使用类来定位按钮,例如:
< button data-id =“'.$row ['id_ktp'].'” class =“ valueButton”>< / button>
然后在您的jQuery中,您可以使用数据API获取值.
$(".valueButton").click(function() {
alert($(this).data('id'));
});
我忽略了以下内容:
>脚本标记错误< script> src =“ jquery-3.3.1.js”< / script>
>丢失< tbody>
>并小心使用auto的“”“,某些编辑器会在您键入时添加它们,以使您始终保持警惕.
标签:html,php,jquery
来源: https://codeday.me/bug/20191211/2105955.html