这就是我所拥有的。我尝试了几件事,但我无法弄清楚我做错了什么......
<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');