<table width="100%"  border="1">
  <tr>
    <td>单价</td>
    <td>数量</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><input name="p1" type="text" id="p1"  onKeyPress="c1.value=parseInt(this.value)*parseInt(s1.value);z.value=parseInt(c1.value)+parseInt(c2.value)"></td>
    <td><input name="s1" type="text" id="s1" onKeyPress="c1.value=parseInt(p1.value)*parseInt(this.value);z.value=parseInt(c1.value)+parseInt(c2.value)"></td>
    <td><input name="c1" type="text" id="c1" readonly="1"></td>
  </tr>
  <tr>
    <td><input name="p2" type="text" id="p2" onKeyPress="c2.value=parseInt(this.value)*parseInt(s2.value);z.value=parseInt(c1.value)+parseInt(c2.value)"></td>
    <td><input name="s2" type="text" id="s2" onKeyPress="c2.value=parseInt(p2.value)*parseInt(this.value);z.value=parseInt(c1.value)+parseInt(c2.value)"></td>
    <td><input name="c2" type="text" id="c2" readonly="1"></td>
  </tr>
  <tr>
    <td colspan="2">合计:</td>
    <td><input name="z" type="text" id="z" readonly="1"></td>
  </tr>
</table>大概思路

解决方案 »

  1.   

    写个函数,先通过该单价和数量所在的table得到行,然后在通过行得到列,把单价和数量的列所得到的值进行计算后,把得到的结果插入到合计的列里
      

  2.   

    同意zghmu007的说法,把这些类似"c1.value=parseInt(this.value)*parseInt(s1.value);z.value=parseInt(c1.value)+parseInt(c2.value)"的做成一个函数。再在每一个<input>中加入一个onblur事件(<input name="名称" onblur="计算的函数">)就可以了。
      

  3.   

    可以用JS写个函数,比如说捕捉鼠标事件,然后通过表单里面读取的值进行相加,如document.form.name.value=document.form.name1.value + document.form.name2.value