简体   繁体   English

在IE 7中意外调用方法或属性访问

[英]Unexpected call to method or property access in IE 7

For work, I need to get our site working in IE7. 为了工作,我需要让我们的网站在IE7中工作。 Because, as we all know, the corporate world can't upgrade. 因为,众所周知,企业界无法升级。

I am using IE8's IE7 emulation mode to test the site, and using IE8's wonderful debugger has been a nightmare. 我使用IE8的IE7仿真模式来测试网站,而使用IE8的精彩调试器一直是个噩梦。

My most recent problem is the following error: 我最近的问题是以下错误:

Unexpected call to method or property access.  jquery.js, line 113 character 460

I've put console.log commands on every line of my function, and figured out the line that's causing the error. 我在我的函数的每一行都放了console.log命令,并找出导致错误的行。

var $loading = $('<span/>').addClass('span-icon icon-ajax-loader').html('Loading...');

This line works fine in Firefox and Chrome. 这条线在Firefox和Chrome中运行良好。 Oh, and it works fine when entering it into IE8's JavaScript console. 哦,它进入IE8的JavaScript控制台时工作正常。

Why would this line give Unexpected call to method or property access ? 为什么这一行Unexpected call to method or property access I think the call to the method or property was totally expected. 我认为对方法或财产的调用是完全可以预料的。

UPDATE: As per @Pointy's suggestion I broke that line into 3 lines. 更新:根据@Pointy的建议,我把这条线分成3行。

var $loading = $('<span/>');
$loading.addClass('span-icon icon-ajax-loader');
$loading.html('Loading...');

Now I'm getting the error on this call $loading.html('Loading...'); 现在我收到了这个电话的错误$loading.html('Loading...'); . Again, if I paste this code into IE8's developer tools and run it, it works fine. 再次,如果我将此代码粘贴到IE8的开发人员工具中并运行它,它可以正常工作。

Where are you injecting the content? 你在哪里注入内容? Have you looked at this question and answer? 你看过这个问题和答案吗? Javascript IE error: unexpected call to method or property access Javascript IE错误:意外调用方法或属性访问

Thanks to @daniellmb and @yoavmatchulsky for helping me fix this issue. 感谢@daniellmb和@yoavmatchulsky帮助我解决了这个问题。

There are actually 3 separate solutions. 实际上有3个独立的解决方案。

Use .text() instead of .html() . 使用.text()代替.html()

var $loading = $('<span/>').addClass('span-icon icon-ajax-loader').text('Loading...');

Wrap the .html() in span tags. 在span标签中包装.html()

var $loading = $('<span/>').addClass('span-icon icon-ajax-loader').html('<span>Loading...</span>');

Or replace $('<span/>') with $('<span></span>') . 或者用$('<span></span>')替换$('<span/>') $('<span></span>')

var $loading = $('<span></span>').addClass('span-icon icon-ajax-loader').html('Loading...');

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM