Voici ce que j'ai. J'ai essayé plusieurs choses mais je ne peux pas comprendre ce que je fais mal ...JQuery Parent() Prochain numéro
<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>
Et le 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);
});
});
L'objectif est lorsqu'un img .voteup est cliqué, pour trouver l'img .votedown correspondant dans le même div VoteControls. Le div ci-dessus fait partie d'une DataList, il y en aura donc beaucoup sur une page.
Ainsi, la partie qui ne fonctionne pas est:
var skullButton = $(this).parent().closest('.votedown');
Êtes-vous en train d'écrire un clone SO? – SLaks
Non. Juste besoin d'un système de vote qui est similaire en ce qu'il n'y a que haut/bas (comme/n'aime pas). Cependant, SO est mon site Web préféré en termes de fonctionnalité, donc tout ce que je peux appliquer à ce que je fais est une victoire. = D – Jason