关于为空必填js判断

为了减少一不必要的if逻辑判断,自已写了一个方法

$(function () {
    $("#btnAdd").click(function () {
        var strLinValu = ".combo-text" + "," +"#txtCpname"+ "," + "#txtCPS" + "," + "#txtPhone" + "," +"#txtFax" + "," + "#txtAddress1"
        if (chkInputVal(strLinValu))
            return false;
        else
            return true;
    });
})

function chkInputVal(strlin) {
    var strArry = strlin.split(',');
    var Flag = false;
    for (var i = 0; i < strArry.length; i++) {
        if ($(strArry[i]).val() == "" || $(strArry[i]).val() == null) {
            $(strArry[i]).focus(); //对应的元素ID获取焦点
            Flag = true;
            break;
        }
    }

    return Flag;
    
}

  

posted @ 2013-12-02 11:25  KyrieYang  阅读(3449)  评论(0编辑  收藏  举报