遍历下数据行就行了,事件改为blur好点,keyup不必要,第一个表格的加个span样式和第二个统一起来,这样好用一个事件就搞定了
<!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" />
<title>无标题文档</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('input').blur(compute)
    })
  function compute(){
    var total=0,num,price,tr,v,rx=/^\d+(\.\d+)?$/
     $(this).closest('table').find('tr:gt(0)').each(function(){
         tr=$(this);
         price=tr.find('input');
         if(price.size()==0||!rx.test(price.val())){ tr.find('span.danhang_sum').html('');return true;}
         num=parseInt(tr.find('td span').html());
         price=parseFloat(price.val())
         v=num*price;
         total+=v;
         tr.find('span.danhang_sum').html(v.toFixed(2));
     }).end().find('span.total_sum').html(total.toFixed(2));
     
  }
</script>
</head>
 
<body>
 
<table width="100%" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <th>数量</th>
    <th>单价</th>
    <th>总价</th>
  </tr>
   
  <tr>
    <td><span id="num">3</span></td>
    <td><input type="text" ></td>
    <td><span  class="danhang_sum"></span></td>
  </tr>
 
  <tr>
      <td colspan="2"><span  style="color:red">总计:</span></td>
    <td><span style="color:red">¥</span><span class="total_sum"></span></td>
  </tr>
</table>
 
<br />
<br />
<br />
<hr>
<br />
<br />
<br />
 
 
<table width="100%" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <th>数量</th>
    <th>单价</th>
    <th>总价</th>
  </tr>
  <tr>
    <td><span id="num">3</span></td>
    <td><input type="text" ></td>
    <td><span class="danhang_sum"></span></td>
  </tr>
  <tr>
    <td><span id="num">8</span></td>
    <td><input type="text" ></td>
    <td><span class="danhang_sum"></span></td>
  </tr>
  <tr>
    <td><span id="num">1</span></td>
    <td><input type="text" ></td>
    <td><span class="danhang_sum"></span></td>
  </tr>
  <tr>
      <td colspan="2"><span  style="color:red">总计:</span></td>
    <td><span style="color:red">¥</span><span class="total_sum"></span></td>
  </tr>
</table>
 
 
 
 
</body>
</html>