2014-04-22 2 views
-1

"+"버튼을 클릭하고 모든 열을 합칠 때마다 행을 만들려고합니다. 열을 만들 수 있습니다. 하지만 행이 없습니다. 사전에Jquery 테이블 합계

$(document).ready(function() { 
    $("#tabla").click(function() { 
     $("tr").find("td:last").before('<td><input type="text" value="0"></td>'); 
     $("tr:last").after('<td><input type="text" value="1"></td>'); 
     $("input").each(function() { 
      $(this).keyup(function() { 
       newSum.call(this); 

      }); 
     }); 
    }); 
}); 


function newSum() { 
    var sum = 0; 
    var thisRow = $(this).closest('tr'); 

    var total = 0; 

    $(thisRow).find("td:not(.total) input").each(function() { 

     sum += parseInt(this.value); 
    }); 
    $(thisRow).find(".total").html(sum); 

    $('.total').each(function() { 

     total += parseInt($(this).html()); 
    }); 
} 

http://jsfiddle.net/YQ7LQ/

감사 :

내 코드입니다.

+0

당신이 JQuery와를 포함하는 기억나요 :

여기
//Sum the Rows. $('#sum_table tr:not(.totalCol) input:text').bind('keyup change', function() { var $table = $(this).closest('table'); var total = 0; var thisNumber = $(this).attr('class').match(/(\d+)/)[1]; $table.find('tr:not(.totalCol) .sum'+thisNumber).each(function() { total += parseInt(this.value); }); $table.find('.totalCol td:nth-child('+thisNumber+')').html(total); }); 

전체 코드입니다 : 여기

코드인가? (당신은 당신의 바이올린에 없었습니다 ...) 또한 : $ ("tr") find ("td : last")'각 행의 마지막 열에 핀을 놓은 다음, 새 열을 만듭니다. 당신은 정말로 새로운 행을 만들 것을 요구하지 않았습니다 ... – leo

+0

나는 나의 바이올린을 업데이트했습니다 – Coluh

답변

0

추가 된 행과 열의 합계가 드디어 문제가 해결 $(document).on('keyup','input',newSum);
Example

+0

고마워요 !, 한가지 질문. 행 결과가 너무 커지도록하려면 행이 가능합니까? – Coluh

+0

@devtreat 무엇을 의미합니까? –

+0

내 피들을 보는 경우 "+"버튼을 클릭하면 열과 행이 증가하고 열을 더할 수 있지만 "+"를 클릭하면 행과 같이 합계가 더 커집니다. – Coluh