javascript jQuery 验证插件,IE7“SCRIPT3:未找到成员”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13462569/
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 plugin, IE7 "SCRIPT3: Member not found"
提问by Joel Kinzel
I have the following:
我有以下几点:
<html>
<head>
</head>
<body>
<div>
<form method="post">
<div id="questions">
<label for="question-6">Name of Course:</label>
<input type="text" name="name_of_course[response]" value="" id="question-6" class="required">
<label class="control-label" for="reporting-year">Reporting Year: </label>
<select name="reporting_year" id="reporting-year">
<option value="-1" selected="selected">Select option...</option>
<option value="4">2013-2014</option>
<option value="1">2012-2013</option>
<option value="2">2011-2012</option>
<option value="3">2010-2011</option>
</select>
</div>
<input type="submit" name="submit" value="Save Entry" class="btn">
</form>
</div>
<script src="//code.jquery.com/jquery.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<script>
$(function(){
jQuery.validator.addMethod("notEqual", function(value, element, param) {
return this.optional(element) || value !== param;
}, "Please select an option");
$('form').validate({
rules:{
'reporting_year': {
notEqual: "-1"
}
}
});
});
</script>
</body>
</html>
Everyone's favorite browser, IE7 (IE10 w/compatibility really) is reporting the following error in the console:
每个人都喜欢的浏览器 IE7(确实兼容 IE10)在控制台中报告以下错误:
SCRIPT3: Member not found.
jquery.js, line 2525 character 4
SCRIPT3:未找到成员。
jquery.js,第 2525 行字符 4
Of course IE8 and above work fine, but my client is using IE7.
当然 IE8 及以上工作正常,但我的客户使用的是 IE7。
回答by danmiser
Looks like it's a bug with IE10 in compatibility mode as it is reported to work in IE7. But there are some jquery workarounds posted here: http://bugs.jquery.com/ticket/12577
看起来它是兼容模式下 IE10 的一个错误,因为据报道它可以在 IE7 中工作。但是这里发布了一些 jquery 解决方法:http: //bugs.jquery.com/ticket/12577
回答by Xaris Fytrakis
What I found causing the problem is line 35 of jquery.validate.js
我发现导致问题的是 jquery.validate.js 的第 35 行
this.attr('novalidate', 'novalidate');
Comment out this line and problem is sovled. You could also wrap it with a ( current browser <= ie7) to explictly avoid this line only when ie7 is the broswer.
注释掉这一行,问题就解决了。您也可以使用 ( 当前浏览器 <= ie7) 将其包装起来,以仅在 ie7 是浏览器时显式避免此行。
UpdateTo comment out line only for ie7 you can use the following code:
更新要注释掉仅适用于 ie7 的行,您可以使用以下代码:
var ie = (function () {
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);
return v > 4 ? v : undef;
} ());
and then:
接着:
if (!ie || ie > 7) {
this.attr('novalidate', 'novalidate');
}
回答by ShibinRagh
Hello problem from jQuery validation
来自 jQuery 验证的你好问题
https://github.com/jzaefferer/jquery-validation/issues/845
https://github.com/jzaefferer/jquery-validation/issues/845
Change line 33 of the jquery Validation plugin from:
将 jquery 验证插件的第 33 行从:
this.attr( "novalidate", "novalidate" );
to
到
this.prop( "novalidate", "novalidate" );
回答by Ben Mills
I was going to add a comment to the answer from Xaris, but wanted to give a little extra info in a full answer. I changed the line in jQuery.validate.js to:
我打算在 Xaris 的答案中添加评论,但想在完整的答案中提供一些额外的信息。我将 jQuery.validate.js 中的行更改为:
if (!$.browser.msie || $.browser.version > 7) {
this.attr("novalidate", "novalidate");
}
However, $.browser was removed from jQuery in version 1.9, so I had to add the jQuery Migrate plugin (this is an official jQuery plugin).
但是,$.browser 在 1.9 版本中从 jQuery 中删除,所以我不得不添加 jQuery Migrate 插件(这是一个官方的 jQuery 插件)。
If you are using nuget packages in .NET and you use the bundling feature, then keep in mind that you can manually update jQuery.validate.js, but the problem will still exist in jQuery.validate.min.js. I had to delete the minified version so that the bundling wouldn't pick it up in production. It's bad practice to be editing the nuget supplied files as my changes will be overwritten when the package is updated, but this is the best fix for this issue right now.
如果你在 .NET 中使用 nuget 包并且你使用了捆绑功能,那么请记住你可以手动更新 jQuery.validate.js,但问题仍然存在于 jQuery.validate.min.js 中。我不得不删除缩小的版本,这样捆绑包就不会在生产中得到它。编辑 nuget 提供的文件是不好的做法,因为更新包时我的更改将被覆盖,但这是目前解决此问题的最佳方法。
回答by falsarella
My similar problem
我的类似问题
I had the same SCRIPT3: Member not found
issue in IE11 due to the defined X-UA-Compatible:
SCRIPT3: Member not found
由于定义了 X-UA-Compatible,我在 IE11 中遇到了同样的问题:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
My solution
我的解决方案
In my case, in these days, the application requirements are IE8+.
就我而言,在这些日子里,应用程序要求是 IE8+。
So, to fix the problem, just remove the meta tag or change it to:
因此,要解决此问题,只需删除元标记或将其更改为:
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
Solution to OP's case (or any similar issue)
OP案例(或任何类似问题)的解决方案
Depending on the compatibility requirements, it may be used the same solution that I used.
根据兼容性要求,可能会使用与我使用的相同的解决方案。