用JS怎样实现对两个复选框内容的大小比较 请大家帮帮忙! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD><SCRIPT LANGUAGE="JavaScript"><!-- function validate(){ var firstPriceList = document.getElementsByName("firstPrice"); var secondPriceList = document.getElementsByName("secondPrice"); var firstPrice = 0; var secondPrice = 0; for (var i = 0; i < firstPriceList.length; i++) { if(firstPriceList[i].checked==true){ firstPrice+=parseInt(firstPriceList[i].value); } } for (var i = 0; i < secondPriceList.length; i++) { if(secondPriceList[i].checked==true){ secondPrice+=parseInt(secondPriceList[i].value); } } if(firstPrice>secondPrice){ alert("我比你大!"); }else{ alert("我不如你大!"); } }//--></SCRIPT> <BODY> <table> <tr> <td> <input type="checkbox" name="firstPrice" checked value="4569"/> <input type="checkbox" name="firstPrice" checked value="1111"/> <input type="checkbox" name="firstPrice"/> <input type="checkbox" name="firstPrice" checked value="3456"/> <input type="checkbox" name="firstPrice" checked value="1234"/> <input type="checkbox" name="firstPrice"/> <input type="checkbox" name="firstPrice" checked value="4589"/> <input type="checkbox" name="firstPrice"/> </td> </tr> <tr> <td> <input type="checkbox" name="secondPrice" checked value="4569"/> <input type="checkbox" name="secondPrice"/> <input type="checkbox" name="secondPrice" checked value="3333"/> <input type="checkbox" name="secondPrice" value="3456"/> <input type="checkbox" name="secondPrice" checked value="1234"/> <input type="checkbox" name="secondPrice"/> <input type="checkbox" name="secondPrice" checked value="4589"/> <input type="checkbox" name="secondPrice"/> </td> </tr> <tr> <td> <input type="button" value=" + " onClick="validate();"/> </td> </tr> </table> </BODY></HTML>这种方法是通用的 你可以用别的方法例如比较两个复选被选中的个数大小来比较 前提是:你说的4位整数是非负的利用这种相加的方法是通用的 unction validate(){ var firstPriceList = document.getElementsByName("firstPrice"); var secondPriceList = document.getElementsByName("secondPrice"); var firstPrice = 0; var secondPrice = 0; for (var i = 0; i < firstPriceList.length; i++) { if(firstPriceList[i].checked==true){ firstPrice+=parseInt(firstPriceList[i].value);} }for (var i = 0; i < secondPriceList.length; i++) { if(secondPriceList[i].checked==true){ secondPrice+=parseInt(secondPriceList[i].value);} }if(firstPrice>secondPrice){alert("我比你大!");}else{alert("我不如你大!");}}//--></SCRIPT> 可以啊! 请教一下JS页面传值的问题 jquery设置 a标签的 状态栏文本 问题 动态隐藏Iframe页面中的滚动条? JavaScript表格 jquery怎样判断多个CheckBox是否被选中, attr只能判断第一个 Firefox下iFrame,window.onresize问题 如何用javascript实现每隔几秒中把字符串写入表格中 JS正则表达式 请帮忙改造一下代码: 关于jQuery实现CheckBox全选、全不选 能用javascript调用api函数么 请问js中[a][b]的表达式是什么意思? WEB页面判断 输入与粘贴
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function validate(){
var firstPriceList = document.getElementsByName("firstPrice");
var secondPriceList = document.getElementsByName("secondPrice");
var firstPrice = 0;
var secondPrice = 0;
for (var i = 0; i < firstPriceList.length; i++) {
if(firstPriceList[i].checked==true){
firstPrice+=parseInt(firstPriceList[i].value);
}
}
for (var i = 0; i < secondPriceList.length; i++) {
if(secondPriceList[i].checked==true){
secondPrice+=parseInt(secondPriceList[i].value);
}
}
if(firstPrice>secondPrice){
alert("我比你大!");
}else{
alert("我不如你大!");
}
}
//-->
</SCRIPT>
<BODY>
<table>
<tr>
<td> <input type="checkbox" name="firstPrice" checked value="4569"/>
<input type="checkbox" name="firstPrice" checked value="1111"/>
<input type="checkbox" name="firstPrice"/>
<input type="checkbox" name="firstPrice" checked value="3456"/>
<input type="checkbox" name="firstPrice" checked value="1234"/>
<input type="checkbox" name="firstPrice"/>
<input type="checkbox" name="firstPrice" checked value="4589"/>
<input type="checkbox" name="firstPrice"/> </td>
</tr>
<tr>
<td>
<input type="checkbox" name="secondPrice" checked value="4569"/>
<input type="checkbox" name="secondPrice"/>
<input type="checkbox" name="secondPrice" checked value="3333"/>
<input type="checkbox" name="secondPrice" value="3456"/>
<input type="checkbox" name="secondPrice" checked value="1234"/>
<input type="checkbox" name="secondPrice"/>
<input type="checkbox" name="secondPrice" checked value="4589"/>
<input type="checkbox" name="secondPrice"/>
</td>
</tr>
<tr>
<td>
<input type="button" value=" + " onClick="validate();"/>
</td>
</tr>
</table> </BODY>
</HTML>
这种方法是通用的
你可以用别的方法
例如比较两个复选被选中的个数大小来比较 前提是:你说的4位整数是非负的
利用这种相加的方法是通用的
var firstPriceList = document.getElementsByName("firstPrice");
var secondPriceList = document.getElementsByName("secondPrice");
var firstPrice = 0;
var secondPrice = 0;
for (var i = 0; i < firstPriceList.length; i++) {
if(firstPriceList[i].checked==true){
firstPrice+=parseInt(firstPriceList[i].value);
}
}
for (var i = 0; i < secondPriceList.length; i++) {
if(secondPriceList[i].checked==true){
secondPrice+=parseInt(secondPriceList[i].value);
}
}
if(firstPrice>secondPrice){
alert("我比你大!");
}else{
alert("我不如你大!");
}
}
//-->
</SCRIPT> 可以啊!