javascript - jQuery IE9 : Unable to get value of the property 'val' : object is null or undefined

标签 javascript jquery internet-explorer

我在 IE9 中收到此错误,指向下面代码片段中的行 return self.subQuantity.val(); 。可能是什么原因造成的?

我应该添加这个在 FF 中完美运行。

部分功能:

$(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

<div class="downgrade">
...
<input type="count" name="count" />
...
</div>

最佳答案

           self = this;

是错误。您正在写信给global self variable (引用window)这里 - 在 IE 中是不可写的。添加var declaration

            var self = this;

它会起作用。

关于javascript - jQuery IE9 : Unable to get value of the property 'val' : object is null or undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8790348/

相关文章:

javascript - 为什么我无法使用 Jquery 显示文本

css - 链接显示但实际上并未在 IE 中定位的 div 内链接

javascript - 如何使状态栏/地址栏在 Firefox 或 IE 中消失?

javascript - 为任何 Function React Typescript 定义 prop 的类型

javascript - javascript中动态添加字段并将数据保存到mysql

javascript - 在 JavaScript 正则表达式中匹配 0-9、a-z 和 1 个特殊字符

javascript - Instafeed 脚本不工作

javascript - 无法使用 Swiffy 对象禁用 html 中的弹跳

javascript - jQuery ajax 验证部分工作

html - 在IE9中,伪元素:after on a TD doesn't get the correct TD height,有解决办法吗?