首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

大神来看看。 复选框有关问题

2013-12-07 
大神来看看。复选框问题本帖最后由 zhouk0619 于 2013-12-05 18:07:05 编辑!doctype htmlhtml langen

大神来看看。 复选框问题
本帖最后由 zhouk0619 于 2013-12-05 18:07:05 编辑

<!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>




怎么才能按照后面的分数相加减。选中加相应的。没选中就减。我就只能做到这个样子了。
老是在判断第一个。  烦死了。在线等。  弄了一天了  ~~~~(>_<)~~~~ 
[解决办法]
按理说没选中的就不管它了嘛!把所有选中的加起来就行!
<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> 


不知道我理解的对不对,你咋写那么多密密麻麻的代码啊?

热点排行