jQuery 验证在 IE7 + IE8 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5942327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Validation not working in IE7 + IE8
提问by magzalez
I'm trying to use the jQuery Validationplugin on a form on my website. The form works in FF, Chrome, Opera and Safari. It has yet to work in IE7 or IE8.
我正在尝试在我网站上的表单上使用jQuery 验证插件。该表单适用于 FF、Chrome、Opera 和 Safari。它尚未在 IE7 或 IE8 中工作。
Below is a simplified version of my code that seems to work in every browser but IE.
下面是我的代码的简化版本,它似乎适用于除 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
编辑:我们现在知道最新使用 jquery,我使用的是 jQuery v1.6,是问题所在。我改回 v1.5.2 改了
var validator = $("form").validate ({
to:
到:
$("form").validate ({
Everything is working in IE, now. Thanks.
现在一切都在 IE 中工作。谢谢。
回答by redsquare
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.
我认为您要么需要返回到较早版本的 jquery (1.5.2),要么使用较新版本的验证插件 1.8.0.1。
回答by Stian
When you create a new ASP.NET MVC 3 Project in Visual studio, your script folder will by default contain among others:
当您在 Visual Studio 中创建新的 ASP.NET MVC 3 项目时,您的脚本文件夹将默认包含以下内容:
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
您可能想要做的第一件事是将 jquery 版本更新到最新版本,现在是1.7.1版
After doing this, your client side validation will stop working in Internet Explorer 7 and Internet Explorer 8.
执行此操作后,您的客户端验证将停止在 Internet Explorer 7 和 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.
这是因为 jquery.validate 版本与 jquery 版本 > 1.6 不兼容。解决方案很简单,您还需要更新您的 jquery.validate 版本。
You can find the current version 1.9 from Microsoft's CDN or the latest version from GitHub here:
您可以从 Microsoft 的 CDN 找到当前版本 1.9 或从 GitHub 此处找到最新版本:
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
微软 Ajax CDN:http: //ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js
GitHub Jquery 验证: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
请记住,您始终可以在 Microsoft 的 CDN 中找到最新的 javascript 库,请在此处查看可用库的完整列表:http: //www.asp.net/ajaxlibrary/cdn.ashx
This information is from my blog postabout this problem
此信息来自我关于此问题的博客文章
回答by ozz
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.
对于它的价值,我不得不升级到最新的 JQuery(此时为 1.8.2)和 Validate(1.10)来解决这个问题。
回答by nullable
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):
我在 IE7/IE8 中遇到了 jquery.validate.js 的问题。调试后,我注意到以下行导致了问题(1.7 版中的 ln 436):
return $([]).add(this.currentForm.elements)
.filter(":input")
Replace these two lines with something like:
用以下内容替换这两行:
return $(':input', this.currentForm)
That did the trick for me.
这对我有用。
回答by kad81
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.
我刚刚遇到了这个问题,但问题不是我需要最新版本的 jquery——是最新版本的 jquery 导致了这个问题。Jquery 2.x 目前不支持 IE,因此请确保您使用的是 1.8+ 但小于 2.0。
回答by MagicalArmchair
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.
我在使用 jqueryui 自动完成的 Sage CRM 上遇到了同样的问题,仅在 IE(版本 10)中出现错误“script3:找不到成员。jquery-1.8.2.min.js,第 2 行字符 32075”。此错误与页面模式有关:IE 正在强制网站进入 IE 7 标准模式。
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">