简体   繁体   English

IE8 appendChild“对方法或属性访问的意外调用”

[英]IE8 appendChild “Unexpected call to method or property access”

I really need some help with this issue I'm having. 对于这个问题,我确实需要一些帮助。 Only seem to have on IE8. 似乎只有在IE8上。 IE7 works fine which is weird. IE7正常工作,这很奇怪。 I'm using IE9 (F2) development tool IE8 emulator which seem to work good. 我正在使用看起来不错的IE9(F2)开发工具IE8仿真器。 I also checked on VMware native IE8 and getting the same results. 我还检查了VMware本机IE8并获得了相同的结果。 Anyway is that a issue with appendChild in IE8? 无论如何,这是IE8中appendChild的问题? How can I solve this issue and is there a jquery or better way of coding this section. 我如何解决此问题,是否有jquery或更好的方法来编码此部分。

IE report this as the issue ** s.appendChild(document.createTextNode(jcode)); IE将其报告为问题** s.appendChild(document.createTextNode(jcode)); ** "Unexpeced call to method or property access" **“对方法或属性访问的意外调用”

for (var i=0; i<showContain.length+1; i++) 
  { 
var s = document.createElement('script');
s.setAttribute('type','text/javascript'); 
var jcode = "$('#showdiv" + i + "').mouseover(function(){$('.showcaseoff').hide(); $('#showcase" + i + "').show()});";
s.appendChild(document.createTextNode(jcode));
document.body.appendChild(s);
} 

Thanks... 谢谢...

This does seem to simply be a limitation in some versions of IE. 在某些版本的IE中,这似乎只是一个限制。 But, you seem open to alternatives: 但是,您似乎可以选择:

How can I rearrange this to work? 我该如何重新安排工作?

I'm guessing this snippet came from frustration that i seemed to change value for the .show() towards the end. 我猜想这个片段来自沮丧, i似乎最终改变了.show()值。 That would be due to JavaScript's current lack of block-level scoping and mixing in the asynchronous nature of .mouseover() , so it would reference i after the loop had already run to completion and incremented it to showContain.length+1 . 那是由于JavaScript目前缺乏.mouseover()异步特性的块级作用域和混合,因此它将在循环运行完成后引用i并将其递增到showContain.length+1

Eventually, you'll be able to use let in place of var to create a block-level i within the loop (the keyword is part of the upcoming ECMAScript 6 standard). 最终,您将能够使用let代替var在循环内创建块级i (关键字是即将到来的ECMAScript 6标准的一部分)。 But, you can currently use a closure to isolate each value of i in its own function scope. 但是,您当前可以使用闭包i每个值隔离在其自己的function范围内。

function eachShowcase(i) {
    $('#showdiv' + i).mouseover(function(){
        $('.showcaseoff').hide();
        $('#showcase' + i).show()
    });
}

for (var i=0; i<showContain.length+1; i++) {
    eachShowcase(i);
}

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

相关问题 JavaScript RunTime错误:appendChild() - 对IE8中的方法或属性的意外调用 - JavaScript RunTime Error : appendChild() - Unexpected call to method or property in IE8 jQuery 1.11.1 appendChild错误IE8(意外调用方法或属性访问) - jQuery 1.11.1 appendChild error IE8 (Unexpected call to method or property access) JavaScript IE appendChild() - 对方法或属性访问的意外调用 - JavaScript IE appendChild() - Unexpected call to method or property access excanvas IE8,对方法或属性访问的意外调用 - excanvas IE8, Unexpected call to method or property access 在jQuery中对IE8上的方法或属性访问进行了意外调用 - Unexpected call to method or property access on IE8 in jQuery this.appendChild(a)-意外调用方法或属性 - this.appendChild(a) - Unexpected call to method or property access 对方法或属性访问的意外调用-appendChild() - Unexpected call to method or property access - appendChild() 为什么此jQuery代码会导致IE8错误:“方法或属性访问意外调用” - Why does this jQuery code cause IE8 error: “UNEXPECTED CALL TO METHOD OR PROPERTY ACCESS” marionettejs attachhtml ie8-意外调用方法或属性 - marionettejs attachhtml ie8 - unexpected call to method or property 在IE 7中意外调用方法或属性访问 - Unexpected call to method or property access in IE 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM