前端代码
修改radio单选按钮的动态选中
前端页面代码
<div class="layui-form-item">
<label class="layui-form-label">订单状态</label>
<div class="layui-input-block">
<span id="orderstatus" style="display: none"></span>
<input type="radio" name="state" id="state1" title="待确定" value="0" checked="checked" >
<input type="radio" name="state" id="state2" title="已确定" value="1" >
<input type="radio" name="state" id="state3" title="已作废" value="2" >
</div>
</div>
JS代码
var sta = r.orderstatus;
var radio = document.getElementsByName("state");
var radioLength = radio.length;
for (var i = 0; i < radioLength; i++) {
if(sta == radio[i].value){
$(radio[i]).next().click();
}
}