<form name="frmGetZM" method="POST" action="?">
<div align="center">
<table border="0" cellpadding="3" cellspacing="0">
<%For i=0 To 2%>
 <tr>
  <%For z=0 To 4%>
  <td><input type="checkbox" name="xm<%=i%><%=z%>" value="<%=name(i,z)%>" onchange="OnSelectStation(document.frmGetZM.tc0,document.frmGetZM.tc1,document.frmGetZM.tc2)"></td>
  <td><input type="text" name="xmtc<%=i%><%=z%>" size="6" value="<%=count(i,z)%>"> 元</td>
  <%next%>
  <td><input style="text-align: right" type="text" name="tc<%=i%>" size="6" ReadOnly> 元</td>
  </tr>
<%next%>
</table>
</div>
</form>asp代码如上。要实现的功能:
每一行文本框(xmtc<%=i%><%=z%>)内的数值,在复选框(xm<%=i%><%=z%>)选中的情况进行相加,结果在每行最后的文本框(tc<%=i%>)内显示。(如需要,也可对原ASP页面做适当改动。)

解决方案 »

  1.   


    <input type="checkbox" name="" value="" onchange="OnSelectStation(this)">
    <script>
    function OnSelectStation(obj){
    if(obj.checked===true){
         加法.....
    }else{

    }
    }
    </script>
      

  2.   

    给个简单的实现方法,楼主根据自己实际情况改造下总数<input type="text" id="total">
    <input type="checkbox" id="cb1" value="1" onclick="countTotal.count(this, 'cbv1')"><input type="text" id="cbv1">
    <input type="checkbox" id="cb2" value="2" onclick="countTotal.count(this, 'cbv2')"><input type="text" id="cbv2">
    <input type="checkbox" id="cb3" value="3" onclick="countTotal.count(this, 'cbv3')"><input type="text" id="cbv3">
    <input type="checkbox" id="cb4" value="4" onclick="countTotal.count(this, 'cbv4')"><input type="text" id="cbv4">var countTotal = function (){
      var totalEl = document.getElementById("total");
      return {
      count : function(self, id){
      var el = document.getElementById(id),
      _value = el.value,
      totalValue = totalEl.value;
      totalEl.value = self.checked ? +totalValue + +_value : +totalValue - +_value;   
      }
      }
     
     }()
      

  3.   


    如果用这种方法,如何将结果输出到tc<%=i%>
      

  4.   

    如果用这种方法,有两个问题
    1、如何取对应的文本框的数值?
    function OnSelectStation(obj)
    {
      if(obj.checked==true)
      {
      s=obj.name
      ss=s.substr(s.length-2)
        ssy+=document.frmGetZM.xmtc+ss.value*1;
      }else
      {
                    
      }
    tc0.value=ssy
    }2、如何将相加的结果输出到tc<%=i%>?
      

  5.   

    你在tc<%=i%>加<div id=" ">,然后你把方法里面的i输入到<div id=" "的id中,一般在复选框里面,很少出现这样<%=i%>表达式,在html中不提倡用这样的表达式。
    js的交互性非常的好,不好好的利用,就浪费了
      

  6.   

    应该是这个意思吧,把value替换成你的name(i,z) 和 count(i,z)<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
    <html><body>
    <form name="frmGetZM" method="POST" action="">
      <div align="center">
        <table border="0" cellpadding="3" cellspacing="0">
          <%For i=0 To 2%>
          <tr>
            <%For z=0 To 4%>
                <td><input type="checkbox" name="xm<%=i%><%=z%>" value="<%=1%>" onclick="OnSelectStation(this, <%=i%>)"></td>
                <td><input type="text" name="xmtc<%=i%><%=z%>" size="6" value="<%=2%>">元</td>
            <%next%>
            <td><input style="text-align: right" type="text" name="tc<%=i%>" size="6" ReadOnly>元</td>
          </tr>
          <%next%>
        </table>
      </div>
    </form>
    <script type="text/javascript">
    function OnSelectStation(chk, row){
    var tr = chk.parentNode.parentNode;
    var inputs = tr.getElementsByTagName("input");
    var count = 0, val;
    for(var i = 0; i < inputs.length-1; i+=2){
    if(inputs[i].checked){
    val = parseInt(inputs[i+1].value, 10);
    if(!isNaN(val)){
    count += val;
    }
    }
    }
    inputs[inputs.length-1].value = count;
    }
    </script>
    </body></html>
      

  7.   

    太感谢楼上了,把parseInt换成parseFloat,测试通过!