Php Jquery选择正确的id
我从数据库创建一个动态表:Php Jquery选择正确的id,php,jquery,ajax,Php,Jquery,Ajax,我从数据库创建一个动态表: //[..]Typical code to fetch data from the database //$exp_id comes from the database <td><input = type = 'hidden' value = '".$exp_id."' id = 'exp_id'/><input type = 'button' id = 'alpha' value = 'a' onclick = $('.ui.small
//[..]Typical code to fetch data from the database
//$exp_id comes from the database
<td><input = type = 'hidden' value = '".$exp_id."' id = 'exp_id'/><input type = 'button' id = 'alpha' value = 'a' onclick = $('.ui.small.modal').modal('show'); /></td>
有什么想法吗?ID必须是唯一的。改用类:
<td>
<input = type = 'hidden' class='saveme' value = '".$exp_id."'/>
<input type = 'button' class='clickme' value = 'a' onclick = $('.ui.small.modal').modal('show'); />
</td>
ID是唯一的。每个元素都需要有一个唯一的ID。循环所有元素并指定ID“exp_ID”对您不起作用-并且它不是有效的标记!使用Css类和类选择器。您的页面正在生成具有相同id的多个元素。user574632正确!我在想一些关于数组的东西,但是你的更好,更容易理解!祝你一切顺利@用户2638842没问题,很高兴我能帮上忙
<td>
<input = type = 'hidden' class='saveme' value = '".$exp_id."'/>
<input type = 'button' class='clickme' value = 'a' onclick = $('.ui.small.modal').modal('show'); />
</td>
$(document).ready(function(){
$('.clickme').click(function(){
id = $(this).parent().find('.saveme').val();
//alert(id);
$.post('find_expert.php',{exp1:id},function(res){
$(".content").html(res);
});
});
});