Home >Web Front-end >JS Tutorial >How to set radio in javascript
How to set radio in javascript: first find the js code part; then set the radio and select it through the "if(data.isDefault==1){...}" method.
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
How to set radio with javascript?
js set radio radio button value selected
html page:
<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 part code:
<script> //js设置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>
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to set radio in javascript. For more information, please follow other related articles on the PHP Chinese website!