1. 程式人生 > >mui開發中獲取單選按鈕、復選框的值

mui開發中獲取單選按鈕、復選框的值

nbsp ++ element pretty 按鈕 選擇 return null 單選按鈕的值

js獲取單選按鈕的值

function getVals(){
    var res = getRadioRes(‘rds‘);
    if(res == null){mui.toast(‘請選擇‘); return;}
    mui.toast(res);
}
function getRadioRes(className){
    var rdsObj = document.getElementsByClassName(className);
    var checkVal = null;
    for(i = 0; i < rdsObj.length; i++){
        if(rdsObj[i].checked){checkVal = rdsObj[i].value;}
    }
    return checkVal;
}
</script>

js獲取復選框的值

function getVals(){
    var res = getCheckBoxRes(‘rds‘);
    if(res.length < 1){
        mui.toast(‘請選擇‘);
        return;
    }
    mui.toast(res);
}
function getCheckBoxRes(className){
    var rdsObj   = document.getElementsByClassName(className);
    var checkVal = new Array();
    var k        = 0;
    for(i = 0; i < rdsObj.length; i++){
        if(rdsObj[i].checked){
            checkVal[k] = rdsObj[i].value;
            k++;
        }
    }
    return checkVal;
}
 

mui開發中獲取單選按鈕、復選框的值