0

2 つの関数を演算子と組み合わせるにはどうすればよいですか?OR ( || ) スクリプトで 2 つの ifs ステートメントを組み合わせたいの ですが、フィドルは次のとおりです

HTML

<form name="formName" method="post" action="#">
<input type="text" name="attendant[email]" size="13" value="">  
<input type="text" name="attendant[email]" size="13" value="">
<input type="text" name="attendant[email2]" size="13" value="">
<input type="text" name="attendant[email2]" size="13" value="">
<input type="submit" name="submit"> 
</form>

脚本

$("form").submit(function(event) {
    if ($("input:text[name='attendant\\[\email\]']", this).filter(function() {
            return $.trim(this.value) == "";
        }).length) {
        window.alert("No member email1 should be empty.");
        event.preventDefault();
    }
        if ($("input:text[name='attendant\\[\email2\]']", this).filter(function() {
            return $.trim(this.value) == "";
        }).length) {
        window.alert("No member email2 should be empty.");
        event.preventDefault();
    }
});
4

2 に答える 2

0

このようなもの:

$("form").submit(function(event) {
    var email1Validation = function() {
        if($("input:text[name='attendant\\[\email\]']", this).filter(function() {
            return $.trim(this.value) == "";
        }).length) {
            window.alert("No member email1 should be empty.");
            return true;
        }
    },
    email2Validation = function() {
        if ($("input:text[name='attendant\\[\email2\]']", this).filter(function() {
            return $.trim(this.value) == "";
        }).length) {
            window.alert("No member email2 should be empty.");
            return true;
        }
    }
    if(email1Validation() || email2Validation()) {
        event.preventDefault();
    }
});
于 2012-11-15T10:01:35.900 に答える
0
$("form").submit(function(event) {
    if ($("input:text[name='attendant\\[\email\]']", this).filter(function() {
            return $.trim(this.value) == "";
        }).length) {
        window.alert("No member email1 should be empty.");

        event.preventDefault();
    }
       else if ($("input:text[name='attendant\\[\email2\]']", this).filter(function() {
            return $.trim(this.value) == "";
        }).length) {
        window.alert("No member email2 should be empty.");

        event.preventDefault();
    }
});

これはあなたがしなければならないことです..それがあなたを助けることを願っています.

于 2012-11-15T10:04:26.987 に答える