javascript設(shè)置radio的方法:首先找到j(luò)s代碼部分;然后通過“if(data.isDefault==1){…}”方法設(shè)置radio選中即可。
本文操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。
javascript怎么設(shè)置radio?
js設(shè)置radio單選框值選中
html頁面:
<div> <label><input type="radio" name="sex" value="1" id="isMale" />男</label> <label><input type="radio" name="sex" value="2" id="isFemale" />女</label> </div>
js部分代碼:
<script> //js設(shè)置radio選中 if(data.isDefault==1){ $("#isMale").attr("checked","checked"); $("#isFemale").removeAttr("checked"); } //獲取選中的input的value和html $("input[type=radio][name=sex]:checked").val(); $("input[type=radio][name=sex]:checked").html(); </script>
【推薦學習:javascript高級教程】