我创建了一个加入事件表,每一行都由事件填充,所以当我点击加入时,图标会改变。我的问题是,当我单击一个事件时,它会更改但不对应于正确的行,即使单击中间行,我单击的只有第一行图标也会更改。
<td>
<a href="#" class="join_now" id="<?php echo $row['event_id'];?>">
<?php $join=$ db->verify_already_join($official_id, $id); if ($join == 0) { echo "
<img src='images/join.png' id='join' width='30' height='30' />"; } else { echo "
<img src='icon/votenow.png' id='join' width='30' height='30' />"; } ?>
</a>
<td>
我的 Ajax JQUERY
<script>
$(document).ready(function () {
var name = <? php echo json_encode($name); ?> ;
var off_id = <? php echo json_encode($official_id); ?> ;
$(".join_now").live("click", function () {
var id_value = $(this).attr("id");
var newSrc = 'icon/votenow.png';
$.ajax({
type: "POST",
url: "join.now.php",
data: "id=" + id_value + "&name=" + name + "&official=" + off_id,
success: function (html) {
if (html == '0') {
$(".err_msg").html("<strong><font color='red'>You have Successfully Join this Event!</font></strong>");
$('#join').attr('src', newSrc);
}
if (html == '1') {
$(".err_msg").html("<strong><font color='red'>You Already Join this Event!</font></strong>");
}
},
beforeSend: function () {
$(".err_msg").html("<strong>Loading...</strong>")
}
});
return false;
});
});
</script>