jQuery issue in Internet Explorer 8

2020-01-24 10:43发布

I am trying to get my jQuery functions to work on IE8. I am loading the library from Google's servers (http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js).

The $(function(){}) is never called. Instead, I get an error Object expected. I opened the developer and ran typeof $ in the console, and it came up as undefined.

I have tried going to other sites that I know use jQuery (jquery.com), and those all work, is there something I might be missing here?

20条回答
啃猪蹄的小仙女
2楼-- · 2020-01-24 11:08

I was having a similar issue. Things worked in IE6, Firefox, and IE8 running in IE7 compatibility mode; but not in 'normal' IE8. My solution was to put this code in the header

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 

As to why jquery isn't working in IE8 I'm unclear.

查看更多
太酷不给撩
3楼-- · 2020-01-24 11:08

The solution is to upgrade to the latest version of jQuery. I had the exact same problem and upgraded to 1.4.2 and it all works fine again in IE8.

Seems to be totally backwards-compatible with all the jQuery 1.3.2 stuff I did as well so no complaints here!

查看更多
放荡不羁爱自由
4楼-- · 2020-01-24 11:09

Some people stumbling on this post might get this issue with jquery and IE8 because they're using >= jQuery v2. Use this code:

<!--[if lt IE 9]>
    <script src="jquery-1.9.0.js"></script>
<![endif]-->
<!--[if gte IE 9]><!-->
    <script src="jquery-2.0.0.js"></script>
<!--<![endif]-->
查看更多
劳资没心,怎么记你
5楼-- · 2020-01-24 11:09

jQuery is not being loaded, this is not likely specific to IE8. Check the path on your jQuery include. statement. Or better yet, use the following to the CDN:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js">
</script>
查看更多
够拽才男人
6楼-- · 2020-01-24 11:09

I had the same issue. The solution was to add the link to the JQuery file as a trusted site in IE.

查看更多
Explosion°爆炸
7楼-- · 2020-01-24 11:10

If you are using HTTPS on your site, you will need to load the jQuery library from Googles https server instead. Try this: https://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js (or the latest https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js)

查看更多
登录 后发表回答