开发者

jQuery not working at all in IE 8

开发者 https://www.devze.com 2023-02-05 10:46 出处:网络
I written some stuff using jQuery and it works great in Chrome. When I tried to open in in IE it looked like jQuery wasn\'t loaded at all... Now I tried the simplest possible jQuery demo and it still

I written some stuff using jQuery and it works great in Chrome. When I tried to open in in IE it looked like jQuery wasn't loaded at all... Now I tried the simplest possible jQuery demo and it still doesn't work...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <script type="text/javascript" src="jquery-1.4.2.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $("a").click(function(e){
            (e.preventDefault();
            $(this).hide("slow").show("fast");
        });   
    });


    </script&g开发者_如何学Ct;
  </head>
  <body>
    <a href="http://jquery.com/">jQuery</a>
  </body>
</html>

The page should hide, then show the link but it just link to the jQuery website when I open it in IE. It works normally in Chrome....


event is a keyword in IE, try changing that parameter to simply e or evt.

Edit: Saying that, this jsFiddle is working fine for me in FF, Chrome and IE.


Try adding a doctype such as this to the top of the page. jQuery will not work when the browser is in quirks mode.

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


remove extra ( you have written before e.preventDefault();


There was an error in code... and extra (. It seems that this didn't bother Chrome...


Replace this...

$(this).hide("slow").show("fast");

with this...

$(this).hide("slow", function () {
    $(this).show("fast")
});

I've not tested this by the way.

0

精彩评论

暂无评论...
验证码 换一张
取 消