日期:2014-05-16 浏览次数:20395 次
<table border="1" id="tb">
<tr><td>个数</td><td>单价</td><td>总价</td></tr>
<tr><td>2</td><td>50</td><td></td></tr>
<tr><td>3</td><td>40</td><td></td></tr>
<tr><td>4</td><td>50</td><td></td></tr>
</table>
<script type="text/javascript">
window.onload = function () {
var tb = document.getElementById('tb'), tr;
for (var i = 1, j = tb.rows.length; i < j; i++) {
tr = tb.rows[i];
tr.cells[2].innerHTML = parseFloat(tr.cells[0].innerHTML) * parseFloat(tr.cells[1].innerHTML);
}
}
</script>
var sum = 0;
$("[id^='_sum['][id$=']']").each(function() {
sum = sum + parseFloat($(this).find("nth-child(3)").text());
});
alert('sum is '+sum);
<!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>
<title></title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script>
$(function () {
$("table tr").each(function () {
var num1 = $(this).find("td:nth-child(1)").text();
var num2 = $(this).find("td:nth-child(2)").text();
$(this).find("td:nth-child(3)").text(parseFloat(num1 * num2));
});
});
&nb