2012-05-11 3 views
0

를 사용하여 부모 TD에서 합계를 퍼팅 나는 table 따라하고 난 parenttd 입력JQuery와

<table cellspacing="0" rules="all" border="1" id="gvSPActivities" style="border-collapse: collapse;"> 
    <tr> 
     <th scope="col"> 
      TextVal1 
     </th> 
     <th scope="col"> 
      TextVal2 
     </th> 
     <th scope="col"> 
      TextVal3 
     </th> 
    </tr> 
    <tr class="gridrow2"> 
     <td> 
      <input name="gvSPActivities$ctl02$TextVal1" type="text" id="gvSPActivities_TextVal1_0" 
       class="numeric" style="width: 150px;" /> 
     </td> 
     <td> 
      <input name="gvSPActivities$ctl02$TextVal2" type="text" id="gvSPActivities_TextVal2_0" 
       class="numeric" style="width: 150px;" /> 
     </td> 
     <td> 
      <input name="gvSPActivities$ctl02$TextVal3" type="text" id="gvSPActivities_TextVal3_0" 
       class="total" style="width: 150px;" /> 

     <table> 

     <tr> 
      <td> 
         <input name="gvSPActivities$ctl02$gvBenefic$ctl02$txtMaleBenefic" type="text" id="gvSPActivities_gvBenefic_0_txtMaleBenefic_0" class="numeric" style="width:100px;" /> 
         </td><td> 
         <input name="gvSPActivities$ctl02$gvBenefic$ctl02$txtFemaleBenefic" type="text" id="gvSPActivities_gvBenefic_0_txtFemaleBenefic_0" class="numeric" style="width:100px;" /> 
         </td> 

       </tr> 


</table> 
      </td> 
    </tr> 

</table> 

덕분에 자식 테이블 inputsum을 넣고 싶다.

답변

0

코드는 정말 난독 그러나 나는 이것이 당신이 찾고있는 무슨 생각 :

$(".gridrow2 td input").onkeyup(function() { 
    var sum = 0; 

    $(".gridrow2 :input").each(function() { 
     sum += $(this).val(); 
    }); 

    $("#gvSPActivities_gvBenefic_0_txtMaleBenefic_0").val(sum); 
}); 

그것은 세 자녀 입력의 합에 "부모 <td> 입력"의 값을 변경합니다. 나는 생각한다.

+0

http://jsfiddle.net/kashifnadeem/fLyq6/5/ – Kashif

+0

왜 나에게 바이올린을주는? :) –

+0

바이올린에서 작동하지 않습니다. 내가 뭔가 잘못하고 있는거야? – Kashif

0
var result = 0; 

$('table > td.gridrow2 > table > td').each(function() { 
    result += parseInt($(this).find('input.numeric').val()); 
}); 

$('td.gridrow2 > td:eq(2) > input[name="gvSPActivities$ctl02$TextVal3"]').val(result); 
+2

스택 오버플로에 오신 것을 환영합니다! 이 코드가 왜 작동하는지 설명하기 위해 서술을 추가하는 것이 좋을까요? 질문에 대한 답을 얻는 방법은 무엇입니까? –

0

총계를 언제 업데이트하겠습니까?이 코드는 언제 사용할 수 있습니까?

$('.gridrow2').each(function(){ 
    var total = 0; 
    $(this).find('table > .numeric').each(function(){ 
     total += this.value; 
    }); 

    $(this).find('.total').val(total); 
});