87,917
社区成员
发帖
与我相关
我的任务
分享
总数<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;
}
}
}()
<input type="checkbox" name="" value="" onchange="OnSelectStation(this)">
<script>
function OnSelectStation(obj){
if(obj.checked===true){
加法.....
}else{
}
}
</script>
<%@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>