(1)在html中,代码如下:(解析:一行"row"为col-xs-12)
<label class="bg-info">公开方式</label> <input id="isOpen" class="form-control formValue" value="" style="display: none;"> <div class="row"> <div class="col-xs-6"> <input type="radio" value="open" id="open">公开 </div> <div class="col-xs-6"> <input type="radio" value="private" id="private" >私密 </div> </div>
(2)在js中,实现单选按钮操作:
$("#open").click(function() { $("#isOpen").val($("#open").val()); $("#private").attr("checked", false); }); $("#private").click(function() { $("#isOpen").val($("#private").val()); $("#open").attr("checked", false); });
如果对单选按钮初始化复制操作:$("#open").attr("checked", true);
或者:$(":radio[value=" +degree+ "]").attr("checked","checked");