我有這個函數創建到另一個文件的請求來更新數據庫:不會爲上點擊一個鏈接更新ID
$('#thumb-up').live('click', function() {
$('#loading').show();
$.ajax({
context: this,
type: 'GET',
url: '/gallery/configurations/required/photo-thumbs.php',
data: 'i=21&t=1',
success: function() {
$('#loading').hide();
$(this).attr('id', 'thumbup-undo').text('Sluta gilla');
$('#thumbup-count').load('/gallery/configurations/required/thumbup-count.php?i=21&t=1');
}
});
});
$('#thumbup-undo').click(function() {
alert('das');
});
當我點擊id爲thumb-up
文本更改如預期的那樣,「Sluta gilla」。當我點擊此鏈接時,同一個標籤的ID將從thumb-up
更改爲thumbup-undo
,並且將出現警報「dsa」。這裏的問題是它沒有出現!我甚至不知道它是否更改爲thumbup-undo
,但我預計它不會。
您可以嘗試代碼here(我縮短了代碼以使演示正常工作)。
我該如何解決這個問題?
在此先感謝
這甚至比Tats_innit的解決方案效果更好!非常感謝! :D – Erik
不客氣:)。順便說一句,你可以替換容器的'body'來容納#thumb-up和#thumbup-undo。我用身體bc我不知道這是你的情況。 –