关于前端处理table里面多个tr,td下求input的值得和

关于前端处理table里面多个tr,td下求input的值的合,我用的easyui框架,有点不一样的地方注意一下

<form data-type="sean_form"  data-param="{box:'',type:'datagrid'}" method="post" >
	<div>
		<table border="1" cellspacing="0" id="tbList">
		     <tr>
		          <td style="width: 600px;text-align: center;">问卷内容</td>
		          <td style="width: 100px;text-align: center">选项</td>
		          <td style="width: 100px;text-align: center;">分数</td>
		      </tr>
		          <tr style="height:50px">
		              <td style="width: 400px;font-size: 10pt;">1111111111111111111</td>
		              <td style="width: 100px;text-align: center;">
		                  <input type="checkbox" onclick="tr(this)"/><input type="checkbox" onclick="fl(this)"/></td>
		              <td style="width: 100px;display: none">
		                  <input class="mark" type="hidden" name="mark[]"  value="0"/>
		              </td>
		         </tr>
		         <tr style="height:50px;">
		              <td style="width: 400px;font-size: 10pt;">2222222222222222222</td>
		              <td style="width: 100px;text-align: center;">
		                  <input type="checkbox" onclick="tr(this)"/><input type="checkbox" onclick="fl(this)"/></td>
		              <td style="width: 100px;display: none" >
		                  <input class="mark" type="hidden" name="mark[]"  value="0"/>
		              </td>
		         </tr>
		         <tr style="height:50px">
		              <td style="width: 400px;font-size: 10pt;">33333333333333333333</td>
		              <td style="width: 100px;text-align: center;">
		                  <input type="checkbox" onclick="tr(this)"/><input type="checkbox" onclick="fl(this)"/></td>
		              <td style="width: 100px;display: none" >
		                  <input class="mark" type="hidden" name="mark[]"  value="0"/>
		              </td>
		         </tr>
		         <tr style="height:50px">
		              <td style="width: 400px;font-size: 10pt;">444444444444444444</td>
		              <td style="width: 100px;text-align: center;">
		                  <input type="checkbox" onclick="tr(this)"/><input type="checkbox" onclick="fl(this)"/></td>
		              <td style="width: 100px;display: none" >
		                  <input class="mark" type="hidden" name="mark[]"  value="0"/>
		              </td>
		         </tr>
		</table>
	<div>	
  <div class="score" style="padding: 0px 40px" id="{$namespace}search5">
      <div class='result' >
        <a href="javascript:;"  class="easyui-linkbutton" data-options="plain:true"style="height:50px;width:60px;margin-left: 240px;" onclick="submit()">提交</a>
                       </div>
                  </div>
              </form>
<script>
	//点击是时重置分数切换checkbox选项
    function tr(obj){
    if($(obj).is(':checked')){
        if($(obj).siblings().is(':checked')){
            $(obj).siblings().attr("checked",false);
        } 
    }
    $(obj).parent().next().children().val('5');
}
//点击否时重置分数切换checkbox选项
function fl(obj){
    if($(obj).is(':checked')){
        if($(obj).siblings().is(':checked')){
           $(obj).siblings().attr("checked",false);
        } 
    }
    $(obj).parent().next().children().val('0');
}
function submit(){
        var tr =$('#tbList').find('.mark');//获取table下标签为mark的input标签
        var len = tr.length;//获取有多少个这样的input标签
        var firstTdText=0;
        for(var i  = 0;i < len;i++){
            var c=tr[i].value*1;//循环获取选中的值,乘以1为了让它被识别为数字
                firstTdText += c;//循环累加
        }
        $('.summark').val(firstTdText);//向存和的标签赋值
        var data =$('#fromsub').serializeJSON();//获提交的取数据
        $.post('__URL__/onpage/json/1',data,function(res){
            if(res.state=="success"){//判断数据是否成功
                 $.messager.alert('消息提醒',res.info,'info') //页面提示
                $.Sean.refreshTabs();//刷新当前页面,重置条件
            }else{
                $.messager.alert('消息提醒',res.info,'warning')  //页面提示
            }
        },'json')
    };
</script>
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值