JQuery无法在Internet Explorer 8中运行

Vis*_*har 2 jquery internet-explorer addclass

我有html如下:

<navi>
    <ul class="fnt_menu_secondo_livello" id="menu_secondo_livello">
        <li><a href="Retailers.aspx" title="Account Set up">Account Set Up</a></li>
        <li><a href="RetailerLogin.aspx" title="Retailer Login">Retailers Login</a></li>
        <li><a href="ManufacturerLogin.aspx" title="Manufacture Login">Manufacturers Login</a></li>
        <li><a href="PriceListRequest.aspx" title="Price List Request">Price List Request</a></li>
        <li><a href="Education.aspx" title="Price List Request">Education</a></li>
    </ul>
</navi>
Run Code Online (Sandbox Code Playgroud)

我正在使用此代码将addClass添加到当前菜单:

$(document).ready(function() {
    $('navi a[href^="' + location.pathname.split("/")[1] + '"]').closest('li').addClass('select');
});
Run Code Online (Sandbox Code Playgroud)

这在除IE8之外的其他浏览器中工作正常.

让我知道这有什么问题.

dak*_*ait 5

要使HTML5元素与非html5兼容的浏览器一起使用,您需要包含htmlshiv http://code.google.com/p/html5shiv/

同时在其他的答案表明它应该是nav代替navi http://www.w3.org/WAI/GL/wiki/Using_HTML5_nav_element

在脚本部分添加以下内容

<!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
Run Code Online (Sandbox Code Playgroud)

并修改选择器

$(document).ready(function() {
    $('nav a[href^="' + location.pathname.split("/")[1] + '"]').closest('li').addClass('select');
});
Run Code Online (Sandbox Code Playgroud)

这是John Resig的博客文章(由@Ravi提供)你可能会发现有用的http://ejohn.org/blog/html5-shiv/