jQuery Validation not working in IE7 + IE8

2019-01-06 13:40发布

I'm trying to use the jQuery Validation plugin on a form on my website. The form works in FF, Chrome, Opera and Safari. It has yet to work in IE7 or IE8.

Below is a simplified version of my code that seems to work in every browser but IE.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

<title>Form</title>

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8/jquery.validate.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
       var validator = $("form").validate ({
       rules: {
                first_name: "required"
              },
       messages: {
                first_name: "Enter your firstname"
                 }
       });
    });
</script>

</head>

<body>

<form method="post">
    <label for="first_name" class="hide">First Name</label> 
    <input type="text" name="first_name" value="" id="first_name" class="required" />
    <button type="submit" id="submit" name="submit">Submit</button>
</form>

</body>

</html>

Edit: We now know that using jquery latest, I was using jQuery v1.6, was the issue. I changed back to v1.5.2 and changed

var validator = $("form").validate ({

to:

$("form").validate ({

Everything is working in IE, now. Thanks.

6条回答
姐就是有狂的资本
2楼-- · 2019-01-06 14:15

When you create a new ASP.NET MVC 3 Project in Visual studio, your script folder will by default contain among others:

jquery-1.5.1.min.js 
jquery.validate.min.js (which is version 1.8.0)

One of the first things you might want to do is update the jquery version to the latest version, which today is version 1.7.1

After doing this, your client side validation will stop working in Internet Explorer 7 and Internet Explorer 8.

This is because the jquery.validate version is not compatible with jquery versions > 1.6. The solutions is simple, you need to update your version of jquery.validate as well.

You can find the current version 1.9 from Microsoft’s CDN or the latest version from GitHub here:

Microsoft Ajax CDN: http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js

GitHub Jquery Validation: https://github.com/jzaefferer/jquery-validation/downloads

Remember that you can always find the latest javascript library in Microsofts CDN, see the complete list of available libraries here: http://www.asp.net/ajaxlibrary/cdn.ashx

This information is from my blog post about this problem

查看更多
Emotional °昔
3楼-- · 2019-01-06 14:17

I had issues with jquery.validate.js in IE7/IE8. After debugging I noticed the following line was causing the issue (ln 436 in version 1.7):

return $([]).add(this.currentForm.elements)
            .filter(":input")

Replace these two lines with something like:

return $(':input', this.currentForm)

That did the trick for me.

查看更多
小情绪 Triste *
4楼-- · 2019-01-06 14:21

For what it's worth, I had to upgrade to latest JQuery (1.8.2 at this time) and Validate (1.10) to get around this issue.

查看更多
做个烂人
5楼-- · 2019-01-06 14:22

I just had this issue but the problem was not that I needed the latest version of jquery--it was the latest version of jquery that caused the issue. Jquery 2.x does not support IE at this time, so make sure you're using 1.8+ but less than 2.0.

查看更多
Evening l夕情丶
6楼-- · 2019-01-06 14:29

I think you either need to move back to an earlier version of jquery (1.5.2) or use the newer version of the validation plugin 1.8.0.1.

查看更多
男人必须洒脱
7楼-- · 2019-01-06 14:35

I had the same problem on Sage CRM using jqueryui autocomplete getting error "script3: member not found. jquery-1.8.2.min.js, line 2 character 32075" only in IE (version 10). This error was tied up in the page mode: IE was forcing the site into IE 7 standard mode.

Its a nasty hack, but it works well. Put this at the start of the page. Cost me an hour tonight messing about with this, hope this helps someone else.

<!DOCTYPE HTML>
<meta http-equiv="x-ua-compatible" content="IE=Edge">
查看更多
登录 后发表回答