UCML 前端非空验证

需要在lable处添加*标识,验证范围:输入框、下拉框、日期框

遍历带*号的

function NoEmptyVerification() {
    var controls = $(".u-label-control:contains('*')");
    for (var i = 0; i < controls.length; i++) {
        var checkID = "";
        var checkName = controls[i].childNodes[1].innerText;
        var Node = controls[i].childNodes[3];
        var nodeName = Node.nodeName;
        if (nodeName == "INPUT" || nodeName == "SELECT") {
            checkID = Node.id;
        } else if (nodeName == "DIV") {
            checkID = Node.childNodes[0].id
        }
        if (checkID != "" && checkName != "") {
            debugger;
            checkID = "#" + checkID;
            var control = $(checkID);
            if (control.val() == "") {
                control.focus();
                alert(checkName + "不能为空!");
                return false;
            }
        }
    }
}

遍历所有控件

function NoEmptyVerification() {
    var controls = $(".u-label-control");
    for (var i = 0; i < controls.length; i++) {
        var control = controls[i];
        var isNoEmpty = control.innerText.indexOf("*");
        if (isNoEmpty != -1) {//非空
            var checkID = "";
            var checkName = "";
            var ParentID = "#" + control.id;
            $(ParentID).contents().filter(function () {
                if (this.nodeName == "LABEL") {
                    checkName = this.innerText;
                } else if (this.nodeName == "INPUT" || this.nodeName == "SELECT") {
                    checkID = this.id;
                } else if (this.nodeName == "DIV") {
                    var className = this.className.replace(/ /g, ".");
                    className = "." + className + " :input";
                    checkID = $(className)[0].id
                }
            });
            if (checkID != "" && checkName != "") {
            debugger;
                checkID = "#" + checkID;
                 var control=$(checkID);
                if (control.val() == "") {
                    control.focus();
                    alert(checkName + "不能为空!");
                    return false;
                }
            }
        }
    }
}

 

你可能感兴趣的:(UCML)