請問數字相減問題

[code="java"]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


$(document).ready(function(){ $('.vTotal').each(function(i) { var vTotal = 0; $(this).parent().parent() .find('td:nth-child(' + (i+2) +'),th:nth-child(' + (i+2) +')') .each(function(i) { vTotal -= parseInt($(this).text()); }); $(this).text(vTotal); }); }); //document End


項目數字1數字2
AAAA6050
BBBB4020
相減:00


[/code]
[img]http://elfkid.net/1.gif[/img]
這個是目前相撿出來的數字不對
請問要如何修改才能讓數字相減變成正確的數值呢

[code="java"]<br><br> $(document).ready(function(){ </p> <pre><code> $(&#39;.vTotal&#39;).each(function(i) { var vTotal = 0; $(this).parent().parent() .find(&#39;td:nth-child(&#39; + (i+2) +&#39;),th:nth-child(&#39; + (i+2) +&#39;)&#39;) .each(function(i) { vTotal = parseInt($(this).text())-vTotal; }); $(this).text(vTotal); }); </code></pre> <p>}); //document End<br><br>



項目數字1數字2
AAAA6050
BBBB4020
相減:00



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


$(document).ready(function(){ $('.vTotal').each(function(i) { var vTotal = 0; $(this).parent().parent() .find('td:nth-child(' + (i+2) +'),th:nth-child(' + (i+2) +')') .each(function(i) { if(vTotal=0)vTotal=parseInt($(this).text); else vTotal -= parseInt($(this).text()); }); $(this).text(vTotal); }); }); //document End


項目數字1數字2
AAAA6050
BBBB4020
相減:00


[code="java"]

  $('.vTotal').each(function(i) {   
      var vTotal = 0;
      var vTotal=0;
      $(this).parent().parent()   
        .find('td:nth-child(' + (i+2) +'),th:nth-child(' + (i+2) +')')   
        .each(function(i)   
        {   if(i==0)  v1=parseInt($(this).text());
            vTotal -= parseInt($(this).text());   
        });   
       vTotal=vTotal+2*v1;
      $(this).text(vTotal);   
  });   

[/code]