2012-05-30 3 views
3

각 행에 숨겨진 필드가있는 테이블이 있습니다. 해당 행의 버튼을 클릭하면 숨겨진 필드 값을 경고해야합니다. 다음 jQuery 코드가 있습니다. 그러나 그것은 효과가 없습니다. 우리가 어떻게 작동하게할까요?테이블 행에 숨겨진 필드 값을 가져 오는 jQuery

CODE : http://jsfiddle.net/Lijo/xWanB/

<script> 
    $(document).ready(function() { 

     //"Show ID" for Associate Button Click 
     $('.resultGridTable tr > td > .actionButtonNational').click(function() { 
      //"this" means show ID button 
      //Traversing to get the parent row and then the required columns in the row 
      var associateID = $(this).parents('tr:first > .wrapperDivHidden input[type=hidden]').val(); 
      alert(associateID); 
      return false; 
     }); 
    }); 
</script> 

HTML

당신의 선택은 tr:first > .wrapperDivHidden ...로 시작하지만 .wrapperDivHidden 지금과 같이 당신의 선택을 변경 tr의 즉각적인 자식이 아닌
<td> 
    XXXXX 
    <input type="submit" name="ctl00$detailContentPlaceholder$grdSubscribedAssociates$ctl04$btnNational" 
         value="Show ID" id="detailContentPlaceholder_grdSubscribedAssociates_btnNational_2" 
         class="actionButtonNational" style="color: White; background-color: #A7A7A6; 
         font-weight: bold; width: 60px" /> 
    <div id="wrapperDivHidden" class="wrapperDivHidden"> 
     <input type="hidden" name="ctl00$detailContentPlaceholder$grdSubscribedAssociates$ctl04$hdnAssociateID" 
          id="detailContentPlaceholder_grdSubscribedAssociates_hdnAssociateID_2"value="789345680" /> 
    </div> 
</td> 

답변

0

은 당신이 뭘 하려는지의 이상 단순화 된 예입니다 var x = $ ('input [type = hidden]', $ (this) .find ("td : first")).

+0

나는 ASP.Net HiddenField와 함께 일하고있다. 그러므로 그것은 나를 위해 일할 수 있습니다. – Lijo

0

:

여기
<script type="text/javascript"> 

    $(document).ready(function() { 
     //"Show ID" for Associate Button Click 
     $('.actionButtonNational').click(function() { 
      var associateID = $('input[type=hidden]', $(this).closest("td")).val(); 
      alert(associateID); 
      return false; 
     }); 
    }); 
</script> 
관련 문제