需要识别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