Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么不是';这个JQuery代码在IE8和IE9上工作吗?_Javascript_Jquery_Html_Internet Explorer 8_Internet Explorer 9 - Fatal编程技术网

Javascript 为什么不是';这个JQuery代码在IE8和IE9上工作吗?

Javascript 为什么不是';这个JQuery代码在IE8和IE9上工作吗?,javascript,jquery,html,internet-explorer-8,internet-explorer-9,Javascript,Jquery,Html,Internet Explorer 8,Internet Explorer 9,此函数使用JQuery中的.load方法更新我的内容。该代码在Google Chrome和Mozilla Firefox上按预期工作,但在IE8和IE9中根本不起作用 内容如下: $(function(){ var newHash=''; $contentwrapper = $("#contentwrapper"); $("nav").delegate(".menuOptions", "click", function() { window.

此函数使用JQuery中的
.load
方法更新我的内容。该代码在Google Chrome和Mozilla Firefox上按预期工作,但在IE8和IE9中根本不起作用

内容如下:

 $(function(){

   var newHash='';
    $contentwrapper = $("#contentwrapper");

    $("nav").delegate(".menuOptions", "click", function() 
    {
        window.location.hash = $(this).attr("href");
        return false;
    });

    $(window).bind('hashchange', function()
    {
        newHash = window.location.hash.substring(1);  
        $contentwrapper.load(newHash + " #contentcolumn");
        setTimeout(TitleUpdater, 200);
    });
 });

 function TitleUpdater()
 {
     top.document.title=$("#contentcolumn").attr("title");
 }
我想知道如何使此代码与Internet Explorer兼容!多谢各位

编辑:在Firefox和Chrome上,此代码只替换了一个大的
,并且所有样式都与脚本执行前保持不变。而IE8和IE9只需通过
..
删除我所有的html代码(它甚至会在
头和
体标记上写入)。这真奇怪

以下是index.html:

<!DOCTYPE html>
<html>
    <head>
        <title>Vladi Manaev</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/bagums.css" media="screen" />
        <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
    </head>

    <body>
        <div id="maincontainer">

            <div id="topsection">
                <div id="banner"></div>
                <div class="navbar">
                    <div class="navbar-inner">
                        <div class="container">
                            <nav> 
                                <a class="brand" href="">Bagums.com</a>
                                <ul class="nav">
                                    <li class="dropdown">
                                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Basic Tutorials<b class="caret"></b></a>
                                        <ul class="dropdown-menu">
                                            <li><a class="menuOptions" href="BasicTutorials/CTutorial.html" name="CTutorial">C</a></li>
                                            <li><a class="menuOptions" href="BasicTutorials/CppTutorial.html" name="CppTutorial">C++</a></li>
                                            <li><a class="menuOptions" href="BasicTutorials/CsharpTutorial.html" name="CsharpTutorial">C#</a></li>
                                            <li><a class="menuOptions" href="BasicTutorials/JavaTutorial.html" name="JavaTutorial">Java</a></li>
                                            <li><a class="menuOptions" href="BasicTutorials/OtherTutorials.html" name="OtherTutorials">Others</a></li>
                                        </ul>
                                    </li>
                                    <li class="dropdown">
                                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">My Projects<b class="caret"></b></a>
                                        <ul class="dropdown-menu">
                                            <li><a class="menuOptions" href="MyProjects/CProject.html">C</a></li>
                                            <li><a class="menuOptions" href="MyProjects/CppProject.html">C++</a></li>
                                            <li><a class="menuOptions" href="MyProjects/CsharpProject.html">C#</a></li>
                                            <li><a class="menuOptions" href="MyProjects/JavaProject.html">Java</a></li>
                                            <li><a class="menuOptions" href="MyProjects/Others.html">Others</a></li>
                                        </ul>
                                    </li>

                                </ul>

                                <ul class="nav pull-right">
                                    <li class="dropdown-toggle"><a class="menuOptions" href="OtherPages/Links.html">Links</a></li>   
                                    <li class="dropdown-toggle"><a class="menuOptions" href="OtherPages/Contact.html">Contact</a></li>
                                    <li class="dropdown-toggle"><a class="menuOptions" href="OtherPages/About.html">About</a></li>
                                </ul>
                            </nav>
                        </div> <!-- container -->
                    </div> <!-- navbar-inner -->
                </div><!-- navbar -->
            </div><!-- topsection -->

            <div id="contentwrapper">
                <div id="contentcolumn" title="Vladi Manaev">
                    <div id="mainPostsTitle">Latest News</div>

                    <div class="postWrapper">
                        <div class="post">
                            <div class="postTitle"><div class="postTitleTxt">Third post on website</div></div>
                            <div class="postInfo"> Aug 4, 2012 @ 7:23 pm</div>
                            <div class="postContent">
                                <p>
                                    CONTENT
                                </p>
                            </div>
                        </div>
                    </div>

                    <div class="postWrapper">
                        <div class="post">
                            <div class="postTitle"><div class="postTitleTxt">Second post on website</div></div>
                            <div class="postInfo"> Aug 4, 2012 @ 7:22 pm</div>
                            <div class="postContent">
                                <p>
                                     CONTENT
                                </p>
                            </div>
                        </div>
                    </div>

                    <div class="postWrapper">
                        <div class="post">
                            <div class="postTitle"><div class="postTitleTxt">First post on website</div></div>
                            <div class="postInfo"> Aug 4, 2012 @ 6:48 pm</div>
                            <div class="postContent">
                                <p>
                                       CONTENT
                                </p>
                            </div>
                        </div>
                    </div>

                </div><!-- contentcolumn -->
            </div><!-- contentwrapper -->

            <div id="footer"> 
                <nav>
                    <div> Copyright &copy; 2012 created by <a class="menuOptions" href="OtherPages/Contact.html"> Vladi Manaev</a></div>
                </nav>
            </div><!-- footer -->

        </div><!-- maincontainer -->

        <!-- Placed at the end of the document so the page load faster -->
        <script type="text/javascript" src="scripts/jquery-1.7.2.js"></script>
        <script type="text/javascript" src="scripts/bootstrap-dropdown.js"></script>


    <script>
     $(function(){

       var newHash='';
        $contentwrapper = $("#contentwrapper");

        $("nav").delegate(".menuOptions", "click", function() 
        {
            window.location.hash = $(this).attr("href");
            return false;
        });

        $(window).bind('hashchange', function()
        {
            newHash = window.location.hash.substring(1);  
            $contentwrapper.load(newHash + " #contentcolumn");
            setTimeout(TitleUpdater, 200);
        });
     });

     function TitleUpdater()
     {
         top.document.title=$("#contentcolumn").attr("title");
     }

</script>

    </body>
</html>

弗拉迪·马纳耶夫
最新消息 网站上的第三篇文章 2012年8月4日下午7:23 内容

网站上的第二篇文章 2012年8月4日下午7:22 内容

网站上的第一篇帖子 2012年8月4日下午6:48 内容

版权及副本;2012创建人 $(函数(){ var newHash=''; $contentwrapper=$(“#contentwrapper”); $(“nav”).delegate(“.menu选项”,“单击”,函数() { window.location.hash=$(this.attr(“href”); 返回false; }); $(窗口).bind('hashchange',function() { newHash=window.location.hash.substring(1); $contentwrapper.load(newHash+“#contentcolumn”); 设置超时(滴定时间,200); }); }); 函数TitleUpdater() { top.document.title=$(“#contentcolumn”).attr(“title”); }
当我将我的href改为以#开头时,如下所示:

<a class="menuOptions" href="#BasicTutorials/CTutorial.html" name="CTutorial">C</a>

它也开始在IE上工作了! 我猜window.location.hash不适用于IE。。。当我用手加上“#”时,问题就解决了


谢谢大家的帮助

什么在IE中不起作用,具体是什么错误?什么事情没有你想象的那么好?什么症状?您是否调试并查看了Ajax调用返回的内容,这是您所期望的吗?您检查过页面以查看添加了什么吗?@jcolebrand$(“nav”)在DOM中找到标记。这不是问题所在,因为
.load
正在启动。问题是
load
正在替换文档体。