這就是我所擁有的。我已經試過幾件事情,但我想不出什麼我做錯了......JQuery Parent()。下一期
<div class="VoteControls" runat="server" visible='<%# User.Identity.IsAuthenticated %>'>
<img style="cursor: pointer; cursor: hand;" src='<%# (bool)Eval("skull") ? "images/skull.png" : "images/skull-bw.png" %>' alt="Vote Down" class="votedown" title='<%# Eval("entry.ID") %>' />
<img style="cursor: pointer; cursor: hand;" src='<%# (bool)Eval("heart") ? "images/heart.png" : "images/heart-bw.png" %>' alt="Vote Up" class="voteup" title='<%# Eval("entry.ID") %>' />
</div>
而且JQuery的:
$(document).ready(function() {
$(".voteup").click(function() {
var id = $(this).attr("title");
var userID = $("HiddenFieldUserID").val();
var skullButton = $(this).parent().closest('.votedown');
alert(skullButton.attr("src"));
registerUpVote("up", id, $(this), skullButton, userID);
});
$(".votedown").click(function() {
var id = $(this).attr("title");
var userID = $("HiddenFieldUserID").val();
var heartButton = $(this).parent().closest('.voteup');
alert(heartButton.attr("src"));
registerDownVote("down", id, heartButton, $(this), userID);
});
});
我們的目標是在點擊一個.voteup IMG時,在相同的VoteControls div中查找相應的.votedown img。上面的div是DataList的一部分,所以在頁面上會有一堆。
所以不工作的部分是:
var skullButton = $(this).parent().closest('.votedown');
你正在編寫SO克隆嗎? – SLaks 2010-03-03 22:26:22
沒有。只需要一個類似的投票系統,只有上/下(喜歡/不喜歡)。然而,從功能角度來說,SO是我最喜歡的網站,所以我可以應用於我所做的任何事情都是一場勝利。 = D – Jason 2010-03-03 23:01:52