这就是我所拥有的。我已经试过几件事情,但我想不出什么我做错了......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