[英]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: 提供的信息:
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文章 ),所以可能发生您的错误,例如:
input
) 没有结束标记的元素( input
) innerHtml
is read-only ( tr
) innerHtml
为只读( tr
)的元素 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.