0

嗨,我正在研究一个项目,它是一个投票脚本。正如你在这个脚本中所想的那样,我试图让用户在 24 小时内投票不超过 1 次。我有一个 php 部分,它工作得很好,我记录了用户的 ip 和投票时间。在 php 部分,我还返回增加后的总票数。在 jquery 部分我想把那个数字放进一个小盒子里。我创建了一个 javascript 变量并将其设为整数

myApp={};

我像这样把jquery返回值放在它上面

myApp.vote=parseInt(result);

例如,如果网站总票数为 10,当用户在发布完成后点击投票结果警报 11 时(一切都在路上),然后我将该数字放入 myApp.vote 我也想将该数字放入这样的跨度中

 $(this).parent().parent().parent().children("#bar-3").find(".bar-percent").eq(0).html(myApp.vote);

这里问题开始 jquery 放入那个跨度旧票数(10)但它必须是 11

$(document).on("click", ".up", function(){
var vote;
var siteId=$(this).parent().parent().parent().find(".g6").attr("siteid");
if(myApp.siteId!=siteId){



$.post("vote.php", {
    siteId: siteId,
    vote:"up"
}, function (result) {
    alert(result);
    myApp={};
    myApp.vote=parseInt(result);


    });
$(this).parent().parent().parent().children("#bar-3").find(".bar-percent").eq(0).html(myApp.vote);
$(this).parent().parent().parent().children("#bar-3").find(".bar-percent").eq(0).animate({
    backgroundColor: "#FFFF00",

    }, 200, function() {
    // Animation complete.
    });



$(this).parent().parent().parent().children("#bar-3").find(".bar-percent").eq(0).animate({
    backgroundColor: "#FFFFFF",

    }, 1000, function() {
    // Animation complete.
    });


}else if(myApp.siteId==siteId){
$(this).parent().append("<span>already voted  </span>").children("span").addClass("alreadyVoted").animate({
opacity: 0,


}, 2000, function() {
// Animation complete.
});;

};



myApp.siteId=siteId;

当我尝试将它们放入 html 调用之间时,我无法选择它,因为 $(this) 没有引用任何内容,这是我的 html 部分,我想选择 1311,但我做不到

<div class="home_img_box p10 mt10">
<div class="g6" siteid="144">
<img class="syn_img" src="../sI/s/youtube_com-13-04-22.jpg">
</div>
<div class="g5">
<h3 class="handle">
youtube
<img id="up" class="up" src="./images/up.png">
<img class="down" src="./images/down.png">
</h3>
<p>youtube</p>
</div>
<img class="hit" src="./images/hit.png" alt="Hit">
<img class="vote" src="./images/vote.png" alt="Hit">
<div id="bar-1" class="jbar jbarPr jqbar horizontal" pr="9">
<span class="bar-label">PR</span>
<span class="bar-level-wrapper">
<span class="bar-level" data-value="9" style="height: 10px; width: 27px; background-color: rgb(214, 71, 71);"></span>
</span>
<span class="bar-percent">9</span>
</div>
<div id="bar-2" class="jbar jbarHit jqbar horizontal" hit="1254">
<span class="bar-label"></span>
<span class="bar-level-wrapper">
<span class="bar-level" data-value="1254" style="height: 10px; width: 0px; background-color: rgb(58, 137, 201);"></span>
</span>
<span class="bar-percent">1254</span>
</div>
<div id="bar-3" class="jbar jbarVote jqbar horizontal" vote="1311">
<span class="bar-label"></span>
<span class="bar-level-wrapper">
<span class="bar-level" data-value="1311" style="height: 10px; width: 0px; background-color: rgb(58, 137, 201);"></span>
</span>
<span class="bar-percent">1311</span>
</div>
</div>
4

1 回答 1

1

将您的html电话放在您传递给的回调中$.post。照原样,您正在启动请求,然后执行动画,而无需等待请求完成。

于 2013-04-27T23:57:47.320 回答