我正在做一个Reddit类似的网站,使用法语,为了完全优化,我获取结果并进行缓存,然后通过jQuery查询每个链接以查看它们是否被投票。
您认为这样优化查询如何?
为什么不起作用! 这是我的代码。
HTML:
<div class="box ajax_div" title="3">
<div class="score">
<a href="#" class="upvote_position" title="post-up-3"><img src="images/up.png" /></a>
<div class="score_position">1</div>
<a href="#" class="downvote_position" title="post-down-3"><img src="images/down.png" /></a>
</div>
<div class="box_info">
<div class="link">
<a href="#" class="text-show"><a href="?show=3" rel="nofollow" class="out">ouioui</a>
</div>
<div class="further">
<span class="date" title="2012-04-25 04:57:05">il y a 13 heures</span> | posté par <a href="?user=david">david</a> dans <a href="?chan=100hp.fr">100hp.fr</a>
</div>
<div class="further_more">
<a href="?show=3"><img src="images/comment.png" />2 commentaires</a> <a href="#" class="save" title="3"><img src="images/save.png" />sauvegarder le lien</a> <a href="#" class="spam" title="3"><img src="images/report.png" />spam?</a>
</div>
</div>
<div class="textbox" style="display:none;">razraz</div>
</div>
JavaScript:
$(".box").each(function(index){
ele = $('.box').eq(index);
$.get("ajax/score.php",
{ idbox: ele.attr('title'), type: "post" },
function(data) {
ele.find(".score_position").html(data);
});
});
我有多个类似的方框,但只影响最后一个。我先尝试了没有使用索引和eq(index),但结果相同。
var
是一个很常见的错误。 - Tadeck