0

jQueryでフォーム送信を無効にしようとしています。jQuery.validate.jsプラグインを確認しましたが、txtQty[]配列が認識されません。

rules : { 'txtQty[]' : {required: true, minlength: 2} }

しかし、それはうまくいきませんでした

これが私の現在のコードです。

txtQty[] == '0' && txtQty == ''

コード:

    $("form#frmCart").submit(function(e) { 
    var err = false;
    var hidCartId = [];
    var hidProductId = [];
    var txtQty = [];
    var artSize = [];
    $("input[name='txtQty\\[\\]']").each(function(index) {
            if($(this).val() != '' || $(this).val() != '0'){
                txtQty.push($(this).attr('value'));
            } else {
                alert("Empty val");
                err = true;
                $(this).focus();
                e.preventDefault(); // Cancel the submit
                return false; // Exit the .each loop


            }
    });

    $("input[name='hidProductId\\[\\]']").each(function(index) { 
            hidProductId.push($(this).attr('value'));
    });

    $("input[name='hidCartId\\[\\]']").each(function(index) {   
            hidCartId.push($(this).attr('value'));
    });

    $("select[name='articleSize\\[\\]']").each(function(index) { 
        if($(this).val() != $(this).attr('value')){
            artSize.push($(this).val());
        } else {
            artSize.push($(this).attr('value'));
        }
    });
    if(err === true){
                e.preventDefault(); // Cancel the submit
                return false; // Exit the .each loop
    } 

    $.ajax({
        cache: false,
        type: "POST",
        url: "cart.php?action=update",
        data: {hidCartId: hidCartId, hidProductId: hidProductId, txtQty: txtQty, size: artSize},
        success: function(result){
            $('#content-container').html(result);       
        }
    });
    return false;

});

アラートも発火しません.......thx

4

1 に答える 1

1

最初の.eachで、変更|| に &&

于 2012-09-06T10:05:49.110 に答える