关于前端处理table里面多个tr,td下求input的值的合,我用的easyui框架,有点不一样的地方注意一下
<from 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>