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:21

I was fixing a template created by somebody else who forgot to include the doctype.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

If you don't declare the doctype IE8 does strange things in Quirks mode.

查看更多
小情绪 Triste *
3楼-- · 2020-01-24 11:24

The onload event does not always work on IE7/8 in <head> ... </head>

You can force it by adding an onload script at the end of your page before the tag as below.

  <script>
    window.onload();
  </script>
</body>
查看更多
孤傲高冷的网名
4楼-- · 2020-01-24 11:26

I had the same problems.

I solved it verifying that IE8 was not configured correctly to reach the SRC URL.

I changed this, it works right.

查看更多
Root(大扎)
5楼-- · 2020-01-24 11:27

The solution in my case was to take any special characters out of the URL you're trying to access. I had a tilde (~) and a percentage symbol in there, and the $.get() call failed silently.

查看更多
老娘就宠你
6楼-- · 2020-01-24 11:28

Write "var" before variables, when you define them. IE8 dies when there is no "var".

查看更多
▲ chillily
7楼-- · 2020-01-24 11:29

Correction:

Check your script include tag, is it using

type="application/javascript" src="/path/to/jquery" 

change to

type="text/javascript" src="/path/to/jquery" 
查看更多
登录 后发表回答