接上一篇“接受数据控制试图” 现在说下,增怎样将被选中的单选按钮,传到后台
html:
<div class="layui-form-item">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
<legend>基础设置</legend>
</fieldset>
<label class="layui-form-label" style="width: 230px;">设备上传位置信息时间间隔设置:</label>
<div id="time1" class="layui-input-block">
<input class="radius1" type="radio" name="time" value="5" title="5分钟"><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div></div></div>
<input class="radius2" type="radio" name="time" value="10" title="10分钟"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div></div></div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label" style="width: 120px;">围栏半径设置:</label>
<div id="range1" class="layui-input-block">
<input class="radius3" type="radio" name="range" value="1" title="1公里" checked="" ><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div></div></div>
<input class="radius4" type="radio" name="range" value="2" title="2公里"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div></div></div>
</div>
</div>
js:
form.on('submit(component)', function(data){
var time = $('#time1 input[name="time"]:checked').val();
var radius = $('#range1 input[name="range"]:checked').val();
//console.log("时间是"+time);
//console.log("范围是"+radius);
var SendData ={
'time': time,
'radius': radius
};
$.ajax({
url:'路径'
,dataType:'json'
,data:SendData
,header: {
'content-type':'application/json',
}
,type:'post'
,success:function(){
alert("保存成功")
},
error:function () {
layer.msg("保存失败")
}
});})
$('ID input[name="name"]:checked').val() 这句代码是获取被选中的单选框的value值