6
4

3 回答 3

10

Your first hint should be that the object is an #<HTMLInputElement> and not a jQuery object. Use $(elem).hasClass('re');

于 2012-10-23T19:26:46.577 回答
2

elem in your code is a DOM Element object, if you want to use jQuery methods you should create a jQuery object first:

if ($(elem).hasClass('re')) {
于 2012-10-23T19:26:29.773 回答
1

You make the class .re part of your jQuery selector and save the if/then:

function required(address)
{
    //object to hold elements not passing validation tests
    var pass = true;
    $('.required.re').each(function(index, elem) {
        console.log(elem);
        var validEmail = validateEmail(address.email);
        if (!validEmail){
            $(this).addClass('nv'); 
        }
    });
}
于 2012-10-23T19:34:26.977 回答