简体   繁体   English

为什么此jQuery代码会导致IE8错误:“方法或属性访问意外调用”

[英]Why does this jQuery code cause IE8 error: “UNEXPECTED CALL TO METHOD OR PROPERTY ACCESS”

EDIT: I'm using jQuery 1.8.3. 编辑:我正在使用jQuery 1.8.3。

In the code below something fails and cause a javascript error in IE8, with the message "UNEXPECTED CALL TO METHOD OR PROPERTY ACCESS". 在下面的代码中,某些操作失败并导致IE8中的javascript错误,并显示消息“方法或属性访问异常”。 Since it's in IE8, it's very hard to pinpoint exactly where the problem occurs. 由于它在IE8中,因此很难准确地确定问题出在哪里。

Can you guys help me figure out what could be the problem here? 你们能帮我弄清楚这里可能是什么问题吗? Is there a jQuery function run here that cause this type of error? 是否在此处运行导致此类错误的jQuery函数?

clsLanguage.prototype.refreshTranslation = function () {

"use strict";

if (!this.disableliveupdate) {
    $('body').unbind('contentchange');
}

// if translation file was found look for elements to translate
    var tmp_cls = this;
    $('[data-language]').each(function () {
        // html element to do the translation on
        var html_element = $(this);
        // look for the elements language in the current language file
        if (tmp_cls.language_strings[html_element.attr('data-language')]) {

            $.each(tmp_cls.language_strings[html_element.attr('data-language')], function (key, value) { 
                if (key === 'innerHTML') {
                    html_element.html(value);
                } else if (key !== 'description') { //we skip description key, is just used as comment of the value
                    html_element.attr(key,value);
                }
            });

        } else {
            html_element.html(html_element.attr('data-language'));
        }

    });
    if (!this.disableliveupdate) {
        $('body').bind('contentchange', function () {
            //console.log('contentchange triggered');
            tmp_cls.refreshTranslation();
        });
    }

};

This is hard to answer without anything more specific than the error message so please try to whittle it down a bit more. 如果没有比错误消息更具体的信息,这很难回答,因此请尝试将其减少一些。 With the info given: 提供的信息:

  1. It could be one of the calls to .html() : 这可能是对.html()的调用之一:

     ... html_element.html(value); ... html_element.html(html_element.attr('data-language')); 

    .html() internally uses .innerHtml . .html() 内部使用.innerHtml Your error could occur because html_element is an element on which that can't be called (see the corresponding MSDN article ), for example: 因为html_element是无法在其上调用的元素(请参见相应的MSDN文章 ),所以可能发生您的错误,例如:

    • elements without closing tag ( input ) 没有结束标记的元素( input
    • elements where innerHtml is read-only ( tr ) innerHtml为只读( tr )的元素
  2. If the page in question includes HTML5-only or custom elements that could also be the cause. 如果有问题的页面包含HTML5自定义元素,也可能是原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在jQuery中对IE8上的方法或属性访问进行了意外调用 - Unexpected call to method or property access on IE8 in jQuery jQuery 1.11.1 appendChild错误IE8(意外调用方法或属性访问) - jQuery 1.11.1 appendChild error IE8 (Unexpected call to method or property access) IE中出现奇怪的jQuery错误:对方法或属性访问的意外调用 - Strange jQuery error in IE: Unexpected call to method or property access IE8 appendChild“对方法或属性访问的意外调用” - IE8 appendChild “Unexpected call to method or property access” excanvas IE8,对方法或属性访问的意外调用 - excanvas IE8, Unexpected call to method or property access JavaScript RunTime错误:appendChild() - 对IE8中的方法或属性的意外调用 - JavaScript RunTime Error : appendChild() - Unexpected call to method or property in IE8 IE中的jQuery错误:意外调用方法或属性 - jQuery error in IE: Unexpected call to method or property 自定义js / jQuery代码仅在IE7和IE8上生成错误:对象不支持此属性或方法 - Custom js/jQuery code is generating error only on IE7 & IE8: Object does not support this property or method jQuery v1.8.3在ie 8中创建错误,即7“对方法或属性访问的意外调用”。 - jQuery v1.8.3 creating error in ie 8 and ie 7 “Unexpected call to method or property access.” IE8/IE7 导致我在调用 jquery 时出错 - IE8/IE7 cause me an error on a jquery call
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM