从jquery验证中排除某些表单元素

时间:2011-10-08 08:23:56

标签: jquery validation

我正在使用一个带有几个文本框元素的表单,我想要验证,而且我不想要的几个,我正在使用jquery .not(),但是我没有得到所需的结果我做了一些ayntax错误或这里的东西是我的代码

function validateRegisterClick(){
    var isValid = true;
    // Validate User Information.
    $('input[type=text], input[type=password]').not(':input[id$=txtMob], :input[id$=txtOfficeNo]').each(function () {
            if ($(this).val().length <= 0) {
                $(this).next()
                       .fadeIn('slow')
                       .removeClass()
                       .addClass('failure')
                       .fadeIn('slow')
                       .text("Can't be blank.");
                isValid = false;
            }
});
}

它还包括txtMob和txtOfficeNo,因为我正在使用外部javascript文件,所以我使用这种语法 - 谢谢 MAC

2 个答案:

答案 0 :(得分:0)

使用 -

排除ID
$('input').not('input[id$=txtMob], input[id$=txtOfficeNo]').each(function () {
    alert($(this).attr('id'));
});

答案 1 :(得分:0)

更改上面代码中的行可以解决问题:

$('input[type=text], input[type=password]').not(':input[type=text][id$=txtMob], :input[type=text][id$=txtOfficeNo]').each(function ()
相关问题