Home JQuery检查字段是否为空
Post
Cancel

JQuery检查字段是否为空

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function checkIsNull() {
    var flag = false;
    var test1 = $('input:radio[name="test1"]:checked').val();
    var test2 = $("#test2").val()

    if (test1) {
        flag = true;
    } else {
        alert("输入框1不能为空!");
        flag = false;
    }
    if (flag && test2) {
        flag = true;
    } else if (flag) {
        alert("输入框2不能为空!");
        flag = false;
    }
    return flag;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
function checkIsNull() {
    var test1 = $('input:radio[name="test1"]:checked').val();
    var test2 = $("#test2").val()

    if (!test1) {
        alert("输入框1不能为空!");
        return;
    }
    if (!test2) {
        alert("输入框2不能为空!");
        return;
    }
}
This post is licensed under CC BY 4.0 by the author.