thinkphp 里jq处理二维数组遍历的值且把checked选中的传入到后台

时间:2021-10-28 17:53:04

页面:

thinkphp 里jq处理二维数组遍历的值且把checked选中的传入到后台


页面代码:

views:为数组

<foreach name="views" item="vo">
<div class="control-group">
<div class="span6">
<label class="control-label">{$key}</label>
<div class="controls sex_3">
<div class="span3">
<label><input class="radio" type="radio" name="{$vo}" value="3" <if condition="$info['data_level'] eq 3">checked</if>> 全部</label>
</div>
<div class="span3">
<label><input class="radio" type="radio" name="{$vo}" value="1" <if condition="$info['data_level'] eq 1">checked</if>> 私有</label>
</div>
<div class="span3">
<label><input class="radio" type="radio" name="{$vo}" value="2" <if condition="$info['data_level'] eq 2">checked</if>> 按层级</label>
</div>

</div>
</div>
</div>
</foreach>

前台代码:



//提交后获取

$('#submit').click(function() {
var data = {};

var data_level = $('.radio');
for(var i=0;i<data_level.length;i++) {
if(data_level.eq(i).is(':checked')){
var key = data_level.eq(i).attr('name');
data[key] = data_level.eq(i).val();
}
}
}