0

I'm trying to figure out how this jquery.each() could work on IE 7:

        var todosOsCampos = $(".validate_mail");

         jQuery.each(todosOsCampos, function(){
            //Verifica e-mail
            email = $(this).val();
            if(email!=''){
                er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;
                if(!er.exec(email)) {
                    erro = 1;
                    $(this).css("border", "solid 1px #F00");
                }   
            }
        });

I'm checking the e-mail but on Ie7 is not working properly

I Thought the problem was solved but I was wrong. I've changed the code like the example of user2246674 asked me to do.

        var todosOsCampos = $(".validate_mail");

        todosOsCampos.each(function(){
            email = this.value;
            console.log(email);
            if(email!=''){
                er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;
                if(!er.exec(email)) {
                    erro = 1;
                    this.style.border = "solid 1px #F00";
                }   
            }
        });

But the IE7 is returning the follow message:

Problem with this web page might prevent it from being displayed properly or functioning properly. In the future...

And then I hit the show details button:

Line: 528
Char: 5
Error: Object does not support this property or method

Code: 0

Line 528 correspond to this

email = this.value;

Someone could help me?

4

1 回答 1

0

我会认为代码可疑 - 并且容易失败 - 因为使用了错误的“每个”。(但谁知道呢;可能会发生令人惊讶的事情。)

有正在使用的jQuery.each(例如$.each(array, ..)):

通用迭代器函数,可用于无缝迭代对象和数组。

.each(例如$(selector).each(..)),应该使用:

遍历一个 jQuery 对象,为每个匹配的元素执行一个函数。

在这种情况下,使用.each遍历 jQuery 对象,例如:

todosOsCampos.each(function(){ .. })

请记住,它$(selector) 总是返回一个 jQuery 对象,它是 0 个或多个匹配元素的集合。

如果在更正使用后问题仍然存在,请使用更多详细信息更新帖子,包括警告/错误消息。

于 2013-09-20T20:51:45.400 回答