<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页面做适当改动。)
<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页面做适当改动。)
<input type="checkbox" name="" value="" onchange="OnSelectStation(this)">
<script>
function OnSelectStation(obj){
if(obj.checked===true){
加法.....
}else{
}
}
</script>
<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;
}
}
}()
如果用这种方法,如何将结果输出到tc<%=i%>
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%>?
js的交互性非常的好,不好好的利用,就浪费了
<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>