如何处理ie8 jquery 对象不支持此属性或方法的错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5173828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:41:02  来源:igfitidea点击:

How to deal with ie8 jquery object doesn't support this property or method Error?

jqueryinternet-explorer-8

提问by crosenblum

This doesn't indicate any error in my javascript code, but in the downloaded jquery.js file, that is a renamed minified jquery 1.3.2 file.

这并不表示我的 javascript 代码中有任何错误,但在下载的 jquery.js 文件中,这是一个重命名的缩小的 jquery 1.3.2 文件。

I am testing some js code, in IE8 that works 100% in firefox and google chrome, before rolling it to production server.

我正在测试一些 js 代码,在 IE8 中,在将其滚动到生产服务器之前,它在 Firefox 和谷歌浏览器中 100% 工作。

But the jquery library itself seems to have issues inside IE8.

但是 jquery 库本身在 IE8 中似乎有问题。

I even tried downloading a new copy of 1.3.2 jquery, and using that instead of the minified version, and it still errors out.

我什至尝试下载 1.3.2 jquery 的新副本,并使用它而不是缩小版本,但它仍然出错。

Then I tried using a the cdn hosted on at code.jquery.com, and it still errored out before even getting to letting my code work or not work.

然后我尝试使用托管在 code.jquery.com 上的 CDN,但在让我的代码工作或不工作之前它仍然出错。

It appears to partially work in IE8, but other jquery on our dev server partially works, and keep's re-iterating, "Object doesn't support this property or method"

它似乎在 IE8 中部分工作,但我们开发服务器上的其他 jquery 部分工作,并不断重复,“对象不支持此属性或方法”

Is there a specific version of jquery that works best in IE8? At least so I can see if there is an issue with my code or not in IE8?

是否有在 IE8 中效果最好的特定版本的 jquery?至少我可以看看我的代码在 IE8 中是否有问题?

Or is there a list of jquery functions that don't work in IE8?

或者是否有在 IE8 中不起作用的 jquery 函数列表?

P.S. Also, I considered upgrading to IE9, to see if that had the same issue, but you can't download IE9, for WinXP, which sucks. I just like WinXP, and there's very little chance of upgrading. Before I had XP, I had Vista on my work pc, which really tanked.

PS 另外,我考虑升级到 IE9,看看是否有同样的问题,但你不能下载 IE9,对于 WinXP,这很糟糕。我就是喜欢WinXP,升级的机会很小。在我使用 XP 之前,我的工作电脑上装有 Vista,这真的很糟糕。

Sorry for little vent, just trying to get this code working and error free...

对不起,小小的发泄,只是想让这段代码正常工作并且没有错误......

Thank You.

谢谢你。



from comment

来自评论

<!--- Include jQuery --->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" charset="utf-8"></script> 

回答by Mohith Thimmaiah

I was getting this prob when I was using xxx.trim() instead of $.trim(xxx). Once I switched this prob went away.

当我使用 xxx.trim() 而不是 $.trim(xxx) 时,我遇到了这个问题。一旦我切换了这个问题就消失了。

回答by Warren

Note: some may also arrive at this page by trying to use jQuery 2 with IE8. jQuery 2 drops support for IE8 (see: http://jquery.com/browser-support/).

注意:有些人也可能通过尝试在 IE8 中使用 jQuery 2 到达此页面。jQuery 2 不再支持 IE8(参见:http: //jquery.com/browser-support/)。

If you need support for IE8, use the latest version of jQuery 1

如果您需要支持 IE8,请使用最新版本的 jQuery 1

回答by rroche

In my experience, jQuery is rarely the issue regardless of the version you might be running, what i typically do to get those nasty bugs out of the way, is to disable|remove any other javascript that you are running on the site (besides jquery), then start enabling 1 by 1 in conjunction with jquery, once you find where the error is hitting try to debug that script, 1 thing that has been really helpful in the past is to do jslint or jshint, if you are not familiar with those tools, they are tools that will help you validate your code and will recommend you improve some of your statements, based on previous developer experiences, JSLint is a more strict tool, i think JSHint will help you a little bit more as it is a little more forgiving in some aspects.

根据我的经验,无论您运行的版本如何,jQuery 都很少成为问题,我通常为消除那些讨厌的错误所做的工作是禁用|删除您在网站上运行的任何其他 javascript(除了 jquery ),然后开始与 jquery 一起启用 1 by 1,一旦找到错误所在,请尝试调试该脚本,过去非常有用的一件事是执行 jslint 或 jshint,如果您不熟悉这些工具,它们是可以帮助您验证代码并建议您改进某些语句的工具,根据以前的开发人员经验,JSLint 是一个更严格的工具,我认为 JSHint 会帮助您更多一点,因为它是在某些方面稍微宽容一点。

Let me know if that was helpful, also try to install IE8 Developer tools :)

让我知道这是否有帮助,也尝试安装 IE8 开发人员工具:)

回答by crosenblum

Basically there was a weird issue in my code, about declaring a variable.

基本上我的代码中有一个奇怪的问题,关于声明一个变量。

So this had nothing to do with jquery loading, but it wouldn't in any way show an error message related to a line in my code.

所以这与 jquery 加载无关,但它不会以任何方式显示与我的代码中的一行相关的错误消息。

As soon as I declared the variable above the logic, it worked, error free.

一旦我在逻辑上方声明了变量,它就可以正常工作,没有错误。

Thanks to everyone for trying.

感谢大家的尝试。

回答by Kaleem Ullah Khan

It could be many reasons but I was facing the same error and I was using

可能有很多原因,但我遇到了同样的错误并且我正在使用

.html().trim();

when I changed it to

当我把它改成

.html()+""; 

it resolved the issue. check the error line and if you are using .trim() after .html(), remove it.

它解决了这个问题。检查错误行,如果您在 .html() 之后使用 .trim(),请将其删除。

回答by Chris Butterworth

I had this issue with a variable called formchanging that tiny thing fixed it.

我有一个名为form更改那个小东西的变量解决了这个问题。

回答by danrichards

This will also happen if you are trying to use ES5 .bind on a callback with your jquery.

如果您尝试在 jquery 的回调中使用 ES5 .bind,也会发生这种情况。

$('#ref').on('click', function() { 
    // do stuff 
}.bind(this));

回答by Wingy

I was experiencing the sames issue, in my case was caused by chaining trim() onto text() functions in ie8

我遇到了同样的问题,在我的情况下是由将 trim() 链接到 ie8 中的 text() 函数引起的

Offending Code was $("td:eq(n)", this).text().trim();

违规代码原为 $("td:eq(n)", this).text().trim();

Changed to: $.trim(("td:eq(n)", this).text());

变成: $.trim(("td:eq(n)", this).text());

Now working.

工作中。