asp.net
  • jquery
  • 2010-03-03 3 views 2 likes 
    2

    다음은 내가 가지고있는 것입니다. 나는 몇 가지를 시도했지만 내가 뭘 잘못 알아낼 수 없습니다 ...JQuery 학부모() 다음 호

    <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'); 
    
    +0

    SO 복제본을 쓰고 있습니까? – SLaks

    +0

    Nope. 위/아래 (싫어함과 같이) 만 있다는 점에서 비슷한 투표 시스템이 필요합니다. 그러나 SO는 기능 측면에서 내가 가장 좋아하는 웹 사이트이므로, 내가하는 일에 적용 할 수있는 모든 것이 승리입니다. = D – Jason

    답변

    6

    당신은 안쪽 부모 요소의을 발견 closest 방법을 오해하고 있습니다.

    $(this).siblings('.votedown')으로 작성해야합니다.

    +0

    나를 이길. +1! –

    +0

    오, 나는 그것을 알았다. 나는 가장 가까운() 대신에 next()가 다음에 작동해서는 안된다고 생각했다. 왜냐하면 그렇게하지 않기 때문입니다. – Jason

    +0

    형제()는 훌륭했습니다. 감사. – Jason

    관련 문제