MUI H5+常見控制元件的使用之單選按鈕
阿新 • • 發佈:2019-02-14
單選
<label>性別</label> <div style="float: left; width: 30%;" class="mui-radio"> <label>男</label> <input id="Gender_male" name="gender" class="gender" disabled="disabled" type="radio" checked="true" /> </div> <div style="float: left; width: 30%" class="mui-radio"> <label>女</label> <input id="Gender_female" name="gender" class="gender" disabled="disabled" type="radio"> </div>
var genderMale = document.getElementById('Gender_male'); //男
var genderFemale = document.getElementById('Gender_female'); //女
Get
var data = {
Gender: getRadioValue('gender'),
function getRadioValue(className){ var rdsObj = document.getElementsByClassName(className); var checkVal = null; for(i = 0; i < rdsObj.length; i++){ if(rdsObj[i].checked){checkVal = rdsObj[i].value;} } if(checkVal=='on'){ return 1; }else{ return 0; } }
Set
if(result.userInfo.Gender == 1) {
genderMale.checked = true;
}
if(result.userInfo.Gender == 0) {
genderFemale.checked = true;
}