如图,选择几个科目,计算出总课费。单科课费*科目数 = 总课费,我是想用按钮来实现计算。但我的按钮是动态生成的。代码在下面。哪位高手帮帮忙,实在是不会了。
<script type="text/javascript">
function jisuan(){
alert("事件");
}
</script>
<input name="<%=rs("id")%>dankekefei" type="text" id="dankekefei" value="100" size="4"></td>
<td height="18" bgcolor="#FFFFFF" class="STYLE1"><div align="center">
<input type="checkbox" name="<%=rs("id")%>shuxue" id="shuxue">
<label for="shuxue">数</label>
<input type="checkbox" name="<%=rs("id")%>yuwen" id="yuwen">
<label for="shuxue">语</label>
<input type="checkbox" name="<%=rs("id")%>yingyu" id="yingyu">
<label for="shuxue">外</label>
<input type="checkbox" name="<%=rs("id")%>wuli" id="wuli">
<label for="shuxue">理</label>
<input type="checkbox" name="<%=rs("id")%>huaxue" id="huaxue">
<label for="shuxue">化</label>
<input type="checkbox" name="<%=rs("id")%>shengwu" id="shengwu">
<label for="shuxue">生</label>
<input type="checkbox" name="<%=rs("id")%>lishi" id="lishi">
<label for="shuxue">史</label>
<input type="checkbox" name="<%=rs("id")%>dili" id="dili">
<label for="shuxue">地</label>
<input type="checkbox" name="<%=rs("id")%>zhengzhi" id="zhengzhi">
<label for="shuxue">政</label>
</div></td>
<td height="18" bgcolor="#FFFFFF" class="STYLE1"><div align="center">
<input name="<%=rs("id")%>jisuankefei" type="button" id="jisuankefei" size="6" value="计算课费" onClick="jisuan()"/>
调用:jisuan(this)
function jisuan(elem){
var tr,dankefei,chk,t,obj = $(elem);
tr = obj.parent().parent().parent();
dankefei = parseFloat(tr.find('#dankekefei').val());
if(isNaN(dankefei) || dankefei <= 0){
alert('请先设置单科费');
return false;
}
chk = tr.find('input[type=checkbox]:checked');
if(chk.length < 1){
alert('没有选择课程');
return false;
}
t = (dankefei * chk.length).toFixed(2);
alert('总费用:'+t);
}
<table>
<tr>
<td><input name="dankekefei" type="text" id="dankekefei" value="100" size="4"></td>
<td height="18" bgcolor="#FFFFFF" class="STYLE1">
<div align="center">
<input type="checkbox" name="shuxue" id="shuxue">
<label for="shuxue">数</label>
<input type="checkbox" name="yuwen" id="yuwen">
<label for="shuxue">语</label>
<input type="checkbox" name="yingyu" id="yingyu">
<label for="shuxue">外</label>
<input type="checkbox" name="wuli" id="wuli">
<label for="shuxue">理</label>
<input type="checkbox" name="huaxue" id="huaxue">
<label for="shuxue">化</label>
<input type="checkbox" name="shengwu" id="shengwu">
<label for="shuxue">生</label>
<input type="checkbox" name="lishi" id="lishi">
<label for="shuxue">史</label>
<input type="checkbox" name="dili" id="dili">
<label for="shuxue">地</label>
<input type="checkbox" name="zhengzhi" id="zhengzhi">
<label for="shuxue">政</label>
</div>
</td>
<td height="18" bgcolor="#FFFFFF" class="STYLE1">
<div align="center"><input name="jisuankefei" type="button" id="jisuankefei" size="6" value="计算课费" onclick="jisuan(this)" />
<input type="text" />
</td>
</tr>
<tr>
<td><input name="dankekefei" type="text" id="dankekefei" value="100" size="4"></td>
<td height="18" bgcolor="#FFFFFF" class="STYLE1">
<div align="center">
<input type="checkbox" name="shuxue" id="shuxue">
<label for="shuxue">数</label>
<input type="checkbox" name="yuwen" id="yuwen">
<label for="shuxue">语</label>
<input type="checkbox" name="yingyu" id="yingyu">
<label for="shuxue">外</label>
<input type="checkbox" name="wuli" id="wuli">
<label for="shuxue">理</label>
<input type="checkbox" name="huaxue" id="huaxue">
<label for="shuxue">化</label>
<input type="checkbox" name="shengwu" id="shengwu">
<label for="shuxue">生</label>
<input type="checkbox" name="lishi" id="lishi">
<label for="shuxue">史</label>
<input type="checkbox" name="dili" id="dili">
<label for="shuxue">地</label>
<input type="checkbox" name="zhengzhi" id="zhengzhi">
<label for="shuxue">政</label>
</div>
</td>
<td height="18" bgcolor="#FFFFFF" class="STYLE1">
<div align="center"><input name="jisuankefei" type="button" id="jisuankefei" size="6" value="计算课费" onclick="jisuan(this)" />
<input type="text" />
</td>
</tr>
</table>
<script type="text/javascript" src="http://cdn.bootcss.com/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
function jisuan(btn) {
var tr = $(btn).closest('tr'),tds=tr.find('td');
var pirce = parseInt(tds.eq(0).find('input').val()) || 0;
var l = tds.eq(1).find(':checkbox:checked').length;
tds.eq(2).find(':text').val(pirce*l)
}
</script>