[英]jQuery IE9: Unable to get value of the property 'val': object is null or undefined
I get this error in IE9, pointing to the line return self.subQuantity.val();
我在IE9中收到此错误,指向行return self.subQuantity.val();
in the snippet below. 在下面的代码段中 What could cause this? 是什么原因造成的?
I should add this works perfectly in FF. 我应该在FF中完美地添加它。
Partial function: 部分功能:
$(document).ready(function() {
plan = (function() {
var plan = {
subQuantity: $('.downgrade .count'),
...
init: function(productCatalog) {
this.prod = productCatalog;
this.reset();
self = this;
this.fetchButton.bind('click', function(e) {
self.fetchScenarii();
return false;
}).filter(function() {
return self.subQuantity.val();
})
}
HTML 的HTML
<div class="downgrade">
...
<input type="count" name="count" />
...
</div>
self = this;
Is the mistake. 是错误的。 You're writing to the global self
variable (a reference back to window
) here - which is non-writable in IE. 您将在此处写入全局self
变量 (返回window
的引用)-在IE中不可写。 Add a var
declaration 添加一个var
声明
var self = this;
and it will work. 它会工作。
it's return as undefined value so what ever you try to make it like val or length will keep give you the same Error Dialog I was facing the Same problem The Solution for this you need to check if the value is undefined or no before you call any method here how I fixed it 它以未定义的值返回,因此无论您尝试使它如何像val或length一样,都将为您提供相同的错误对话框。方法在这里我如何解决
if (typeof $("#<%=hdnSupplierDialog.ClientID%>").val() === "undefined")
return;
I just prevent the Code to be called in case the value is undefined I wish it works for you :) 我只是防止在未定义值的情况下调用该代码,希望它对您有用:)
Change 更改
return self.subQuantity.val();
to 至
return self.subQuantity.attr("value");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.