0
我創建了一個連接事件表,每行都由事件填充,所以當我點擊連接時,圖標將會改變。我的問題是,當我點擊一個事件時,它改變的圖標,但不對應一個正確的行,我只點擊第一行圖標,即使我點擊中間行也會改變。更改img scr基於點擊圖標
<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>
我阿賈克斯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>
@G Siry我使用id ='join'爲img –
@G Siry好生病嘗試謝謝:D –
@G Siry $('#'+ id_value).attr('src',newSrc);它不會更改圖標。 :( –