【问题标题】:Microsoft JScript runtime error: Unable to get value of the property 'defaultView': object is null or undefinedMicrosoft JScript 运行时错误:无法获取属性“defaultView”的值:对象为空或未定义
【发布时间】:2012-03-10 15:25:40
【问题描述】:

我的 asp.net mvc 中有以下脚本:-

function deleteconfirmation() {

    jAlert('The Answer was deleted succsfully', 'Deletion Confirmation');
    $(this).fadeOut('slow', function () { $(this).remove(); });

}

但是当它被执行时,它将在 jquery-1.6.2 中的if(!(e=a.ownerDocument.defaultView)) 上返回以下错误“Microsoft JScript 运行时错误:无法获取属性‘defaultView’的值:对象为空或未定义”。 min.js。 提示:- 这个错误只会在我使用 IE 时出现,如果我使用 chrome 或 firefox 则不会出现!!!! 那么可能是什么原因造成的呢? BR

【问题讨论】:

    标签: jquery asp.net-mvc-3


    【解决方案1】:

    该错误是由于您的$(this) 没有引用任何内容,或者window object 而导致。这取决于你的函数是如何被调用的。最好将要使用的元素传递给函数deleteConfirmation(),如下所示:

    $("#deleteAnswer").bind("click", function() {
        deleteConfirmation(this);
    });
    
    function deleteConfirmation(element) {
        jAlert('Deleted succsfully', 'Deletion Confirmation', function() {
            alert("The user clicked ok");
    
            // Hides the element that caused the click event
            $(element).fadeOut('slow', function () { $(element).remove(); });
        });
    }
    

    请参阅此jsfiddle 以获取示例。

    如果您尝试fadeOut 警报框本身,默认情况下会这样做,您可能已经知道了。

    【讨论】:

      【解决方案2】:

      我想你忘记添加 jQuery 库的引用了。请检查并添加到jQuery Reference

      另一种可能是忘记在你正在使用的页面中添加jAlert的引用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多