大神来看看。 复选框问题

凯凯灬 2013-12-05 06:04:35
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script type="text/javascript">
function aa()
{
var fxcb_v=document.getElementsByName("FXCB");
var hj=document.getElementById("FXCBFZ");
if(fxcb_v[0].checked==true)
{
var bb= parseInt(fxcb_v[0].value.substr(fxcb_v[0].value.length-7,1));
hj.value=parseInt(hj.value)+parseInt(bb);
}else if(fxcb_v[0].checked==false)
{
var bb= parseInt(fxcb_v[0].value.substr(fxcb_v[0].value.length-7,1));
hj.value=parseInt(hj.value)-parseInt(bb);
}else if(fxcb_v[1].checked==true)
{
var cc= parseInt(fxcb_v[1].value.substr(fxcb_v[1].value.length-7,1));
hj.value=parseInt(hj.value)+parseInt(cc);
}else if(fxcb_v[1].checked==false)
{
var cc= parseInt(fxcb_v[1].value.substr(fxcb_v[1].value.length-7,1));
hj.value=parseInt(hj.value)-parseInt(cc);
}else if(fxcb_v[2].checked==true)
{
var dd= parseInt(fxcb_v[2].value.substr(fxcb_v[2].value.length-7,1));
hj.value=parseInt(hj.value)+parseInt(dd);
}else if(fxcb_v[2].checked==false)
{
var dd= parseInt(fxcb_v[2].value.substr(fxcb_v[2].value.length-7,1));
hj.value=parseInt(hj.value)-parseInt(dd);
}else if(fxcb_v[3].checked==true)
{
var ee= parseInt(fxcb_v[3].value.substr(fxcb_v[3].value.length-7,1));
hj.value=parseInt(hj.value)+parseInt(ee);
}else if(fxcb_v[3].checked==false)
{
var ee= parseInt(fxcb_v[3].value.substr(fxcb_v[3].value.length-7,1));
hj.value=parseInt(hj.value)-parseInt(ee);
}else if(fxcb_v[4].checked==true)
{
var ff= parseInt(fxcb_v[4].value.substr(fxcb_v[4].value.length-7,1));
hj.value=parseInt(hj.value)+parseInt(ff);
}else if(fxcb_v[4].checked==false)
{
var ff= parseInt(fxcb_v[4].value.substr(fxcb_v[4].value.length-7,1));
hj.value=parseInt(hj.value)-parseInt(ff);
}else if(fxcb_v[5].checked==true)
{
var gg= parseInt(fxcb_v[5].value.substr(fxcb_v[5].value.length-7,1));
hj.value=parseInt(hj.value)+parseInt(gg);
}else if(fxcb_v[5].checked==false)
{
var gg= parseInt(fxcb_v[5].value.substr(fxcb_v[5].value.length-7,1));
hj.value=parseInt(hj.value)-parseInt(gg);
}else if(fxcb_v[6].checked==true)
{
var hh= parseInt(fxcb_v[6].value.substr(fxcb_v[6].value.length-7,1));
hj.value=parseInt(hj.value)+parseInt(hh);
}else if(fxcb_v[6].checked==false)
{
var hh= parseInt(fxcb_v[6].value.substr(fxcb_v[6].value.length-7,1));
hj.value=parseInt(hj.value)-parseInt(hh);
}else if(fxcb_v[7].checked==true)
{
var ii= parseInt(fxcb_v[7].value.substr(fxcb_v[7].value.length-7,1));
hj.value=parseInt(hj.value)+parseInt(ii);
}else if(fxcb_v[7].checked==false)
{
var ii= parseInt(fxcb_v[7].value.substr(fxcb_v[7].value.length-7,1));
hj.value=parseInt(hj.value)-parseInt(ii);
}else if(fxcb_v[8].checked==true)
{
var jj= parseInt(fxcb_v[8].value.substr(fxcb_v[8].value.length-7,1));
hj.value=parseInt(hj.value)+parseInt(jj);
}else if(fxcb_v[8].checked==false)
{
var jj= parseInt(fxcb_v[8].value.substr(fxcb_v[8].value.length-7,1));
hj.value=parseInt(hj.value)-parseInt(jj);
}else if(fxcb_v[9].checked==true)
{
var kk= parseInt(fxcb_v[9].value.substr(fxcb_v[9].value.length-7,1));
hj.value=parseInt(hj.value)+parseInt(kk);
}else if(fxcb_v[9].checked==false)
{
var kk= parseInt(fxcb_v[9].value.substr(fxcb_v[9].value.length-7,1));
hj.value=parseInt(hj.value)-parseInt(kk);
}

}
</script>
</head>
<body>
<table>
<tr>
<td onclick="aa();">
<input type=checkbox name=FXCB value='合同主体是分公司或代表处,提供总公司授权书,并约定合同履行的所有责任由总公司承担---3分<br/>'>合同主体是分公司或代表处,提供总公司授权书,并约定合同履行的所有责任由总公司承担---3分<br/></label><label><input type=checkbox name=FXCB value='合同主体是分公司或代表处,提供境内知名企业作为担保---1分<br/>'>合同主体是分公司或代表处,提供境内知名企业作为担保---1分<br/></label><label><input type=checkbox name=FXCB value='业主将合同转移至第三方(如总包,设计院,家具厂商),业主又不愿担保及提供保障。---5分<br/>'>业主将合同转移至第三方(如总包,设计院,家具厂商),业主又不愿担保及提供保障。---5分<br/></label><label><input type=checkbox name=FXCB value='付款节点,非我司所能控制(如业主取得LEED认证后,再付尾款等)---2分<br/>'>付款节点,非我司所能控制(如业主取得LEED认证后,再付尾款等)---2分<br/></label><label><input type=checkbox name=FXCB value='工程进度紧且延迟罚款 > 0.1%,违约赔偿高(Liquidated damage)---3分<br/>'>工程进度紧且延迟罚款 > 0.1%,违约赔偿高(Liquidated damage)---3分<br/></label><label><input type=checkbox name=FXCB value='追加减先做后谈,完工后结算且结算期长---2分<br/>'>追加减先做后谈,完工后结算且结算期长---2分<br/></label><label><input type=checkbox name=FXCB value='保函为无条件、即期的/业主模板---3分<br/>'>保函为无条件、即期的/业主模板---3分<br/></label><label><input type=checkbox name=FXCB value='法律适用外国法律,且在外国法院。业主不同意加上输方支付赢方全额律师费,仲裁费及到当地之差旅费---5分<br/>'>法律适用外国法律,且在外国法院。业主不同意加上输方支付赢方全额律师费,仲裁费及到当地之差旅费---5分<br/></label><label><input type=checkbox name=FXCB value='争议解决并非中国国际经济贸易仲裁委员会 及上海、北京、广州、深圳当地法院的,有地方保护可能---5分<br/>'>争议解决并非中国国际经济贸易仲裁委员会 及上海、北京、广州、深圳当地法院的,有地方保护可能---5分

</td>
<td>
<input type="text" id="FXCBFZ" value=0>
</td>
</tr>
</table>

</body>
</html>



怎么才能按照后面的分数相加减。选中加相应的。没选中就减。我就只能做到这个样子了。
老是在判断第一个。 烦死了。在线等。 弄了一天了 ~~~~(>_<)~~~~
...全文
185 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
凯凯灬 2013-12-06
  • 打赏
  • 举报
回复
引用 3 楼 hzw2312 的回复:
按理说没选中的就不管它了嘛!把所有选中的加起来就行!
<td onclick="WhetherChecked();">

function WhetherChecked(){
     var oChecked = document.getElementsByName("FXCB");              
     var sum = 0 ;  
     for(var i=0;i<oChecked.length;i++){
     var kk = parseInt(oChecked[i].value.substr(oChecked[i].value.length - 7, 1));
     	if(oChecked[i].checked){
        	sum += kk ;
        }
     } 
     alert(sum) ;
}
但是如果说是非要把没选中的分数减掉的话也很简单啊:

function WhetherChecked(){
     var oChecked = document.getElementsByName("FXCB");              
     var sum1 = 0 ;  //加
     var sum2 = 0 ; //减
     for(var i=0;i<oChecked.length;i++){
    	var kk = parseInt(oChecked[i].value.substr(oChecked[i].value.length - 7, 1));
     	if(oChecked[i].checked){
        	sum1 += kk ;
        }else{
        	sum2 += kk ;
        }
     } 
     alert("选中的和:"+sum1+"   -  没选中的和:"+sum2);
}   
</script> 
不知道我理解的对不对,你咋写那么多密密麻麻的代码啊?
大神 , QQ留下
BUG胡汉三 2013-12-05
  • 打赏
  • 举报
回复
按理说没选中的就不管它了嘛!把所有选中的加起来就行!
<td onclick="WhetherChecked();">

function WhetherChecked(){
     var oChecked = document.getElementsByName("FXCB");              
     var sum = 0 ;  
     for(var i=0;i<oChecked.length;i++){
     var kk = parseInt(oChecked[i].value.substr(oChecked[i].value.length - 7, 1));
     	if(oChecked[i].checked){
        	sum += kk ;
        }
     } 
     alert(sum) ;
}
但是如果说是非要把没选中的分数减掉的话也很简单啊:

function WhetherChecked(){
     var oChecked = document.getElementsByName("FXCB");              
     var sum1 = 0 ;  //加
     var sum2 = 0 ; //减
     for(var i=0;i<oChecked.length;i++){
    	var kk = parseInt(oChecked[i].value.substr(oChecked[i].value.length - 7, 1));
     	if(oChecked[i].checked){
        	sum1 += kk ;
        }else{
        	sum2 += kk ;
        }
     } 
     alert("选中的和:"+sum1+"   -  没选中的和:"+sum2);
}   
</script> 
不知道我理解的对不对,你咋写那么多密密麻麻的代码啊?
Defonds 2013-12-05
  • 打赏
  • 举报
回复
纯 js,好辛苦哦。何不换 jQuery,强大的选择器
yuanjianbin 2013-12-05
  • 打赏
  • 举报
回复
你的代码里只有一个if,其它都是else if,当然是这样了

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧