简体   繁体   English

jQuery IE9:无法获取属性'val'的值:对象为null或未定义

[英]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.

相关问题 IE9兼容模式错误:无法获取属性“ 0”的值:对象为null或未定义 - IE9 Compatibility Mode Error: Unable to get value of the property '0': object is null or undefined IE9 JavaScript 错误:SCRIPT5007:无法获取属性“ui”的值:对象为空或未定义 - IE9 JavaScript error: SCRIPT5007: Unable to get value of the property 'ui': object is null or undefined IE9中Magento的Lightbox JS错误-无法获取属性“ 0”的值:对象为null或未定义 - Lightbox JS Error on Magento in IE9 - Unable to get value of the property '0': object is null or undefined IE9中的Angular 1/2混合应用程序错误:“ TypeError:无法获取属性&#39;ref&#39;的值:对象为null或未定义” - Angular 1/2 hybrid app error in ie9: “TypeError: Unable to get value of the property 'ref': object is null or undefined” Microsoft JScript运行时错误:无法获取属性&#39;checked&#39;的值:对象为null或仅在IE9中未定义 - Microsoft JScript runtime error: Unable to get value of the property 'checked': object is null or undefined only in IE9 在IE9中加载页面时如何防止“无法获取属性&#39;dir&#39;的值:对象为空或未定义”错误 - How to prevent “Unable to get value of the property 'dir': object is null or undefined” error when loading pages in IE9 IE9 JS无法获取属性&#39;display&#39;的值:object为null或undefined - IE9 JS Unable to get value of the property 'display': object is null or undefined 使用IE9设置表单输入值(出现错误-无法设置属性“值”的值:对象为null或未定义) - Setting a Form Input Value With IE9 (Getting An Error - Unable to set value of the property 'value': object is null or undefined) IE9无法获取未定义或空引用的属性“删除” - IE9 unable to get property 'remove' of undefined or null reference (IE9)无法获取未定义或空引用的属性&#39;dispatchEvent&#39; - (IE9)Unable to get property 'dispatchEvent' of undefined or null reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM