需要識別div中的每個'a'標籤並綁定onclick事件。我綁定了相同的標籤。我需要在點擊的'a'標籤下添加一些文本。但是當我嘗試我的代碼綁定到div中的所有'a'標籤。我可以如何指定我點擊過的'a'標籤。我可以使用jquery對div中的內容進行更改。可以修改'a ' 標籤。確定標籤
<div class="people_rt_link2">
<a href="#" title="2011">2011</a><br><br>
<a href="#" title="2008">2008</a><br><br>
</div>
$(document).ready(function() {
var timesClicked = 0;
$('.people_rt_link2 a').bind('click', function() {
jQuery.post("<?php bloginfo('template_directory'); ?>/test.php", data, function(response) {
alert('Got this from the server: ' + response);
//this response should to binded to the clicked a tag
//$(this).after('<div>'+response+'</div>');
});
timesClicked++;
if (timesClicked >= 1) {
$(this).unbind();
}
});
});
paulPRO嗨,我有這樣的解決方案,它的工作原理fine.But我怎樣才能達到同樣的一個jQuery post.On的一個標籤內單擊ajax被執行,我需要從服務器獲取響應並將其附加到單擊的錨定標記。 – Gins
@Gins,我更新了我的帖子,向'somepage.php'發出POST請求,並在ajax請求完成後插入數據。 – Paulpro
嗨,我試過這個,但不工作。 – Gins