gpt4 book ai didi

mysql - Ajax/JQuery id 引用多个表行

转载 作者:行者123 更新时间:2023-11-29 06:17:58 25 4
gpt4 key购买 nike

将特定 ID 分配给从表中选择的各种项目列表时遇到问题,以便用户可以单击该项目,从而执行一些 Ajax/Jquery 等。

/** this code had been cut, '$row' is required **/
while($row = mysql_fetch_array($sql)){
echo "<tr><td>
<a id='event_add' title='Add Event' href='javascript:void(0)'>
<img border='0' src='add_button.gif' width='25' height='25'/></a>
</td></tr>";
}

是否可以像这样使用以下内容轻松引用 id?

    $('#event_add').click(function(){
var row = ($(this).parent().parent().children().index($(this).parent()))-1;
$.ajax({
type: "GET",
url: "add_event.php",
data: "row="+row+"&do=addEvent",
cache: false,
async: false,
success: function(result){
alert(result);
},
error: function(result){
alert(result);
}
});
});

任何有关此问题的建议将不胜感激! :)

最佳答案

你为什么不使用

Class id 实例

改变

html

id='event_add'class='event_add'

脚本

$('#event_add')$('.event_add')

关于mysql - Ajax/JQuery id 引用多个表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5415680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com