請問數字相減問題
[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(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
</script>
</head>
<body>
<table>
<thead>
<tr>
<td>項目</td>
<td>數字1</td>
<td>數字2</td>
</tr>
</thead>
<tbody>
<tr>
<td>AAAA</td>
<td>60</td>
<td>50</td>
</tr>
<tr>
<td>BBBB</td>
<td>40</td>
<td>20</td>
</tr>
<tr>
<th>相減:</th>
<th class="vTotal">0</th>
<th class="vTotal">0</th>
</tr>
</tbody>
</table>
</body>
</html>[/code][img]http://elfkid.net/1.gif[/img]
這個是目前相撿出來的數字不對
請問要如何修改才能讓數字相減變成正確的數值呢 [b]回復 [url=http://jsgears.com/redirect.php?goto=findpost&pid=1499&ptid=518]1#[/url] [i]awelkije[/i] [/b]
要不要先解釋一下你目前的思路? 已經想出來解決了 要不要分享一下呢?
頁:
[1]