我似乎无法从 $.post 部分中访问 $(this) 。它在外面工作得很好。这是javascript:
$('.idea').each(function(){
var title = $(this).html();
$.post("votes.php", { title: title }, function(data){
$(this).nextAll('.voteTotal').html(data);
}, "json");
});
HTML:
<h3 class="idea">Idea #1</h3>
<h4 class="voteTotal"></h4>
<p>This is a really cool idea.</p>
<a href="#" class="vote">Click to vote</a>