多级下拉菜单CSS JS:不使用IE

时间:2015-04-20 13:48:43

标签: javascript html css drop-down-menu internet-explorer-11

IE11的问题,我在Chrome和FireFox中使用了下拉式多级(下拉)菜单,但没有使用IE11,这样我可以将菜单更改为一个文件,而不必去到每一页改变菜单。我需要三级菜单。(感谢Frogmouth提供帮助以使其正常工作): multi-level (drop down) menu css js

我尝试过不同的HTML!DOCTYPE但无效。

如何解决这个IE菜单问题?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>PHP Demo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

<link href="site123.css" rel="stylesheet">
</head>
<body>

<nav id="nav01"></nav>

<script type="text/javascript" language="javascript" src="Menu-Script.js"></script>


<div id="main">


<h1>Welcome to Our Site</h1>
<h2>Web Site Main Ingredients:</h2>

<p>Pages (HTML)</p>
<p>Style (CSS)</p>
<p>Code (JavaScript)</p>


<footer id="foot01"></footer>
</div>

</body>
</html> 

我有CSS(文件名:site123.css)

ul#third-level-menu
{
position: absolute;
top: 0;
right: -150px;
width: 150px;
list-style: none;
padding: 0;
margin: 0;
display: none;
}

ul#third-level-menu > li
{
height: 30px;
background: #999999;
}

ul#third-level-menu > li:hover { background: #CCCCCC; }

ul#second-level-menu
{
position: absolute;
top: 30px;
left: 0;
width: 150px;
list-style: none;
padding: 0;
margin: 0;
display: none;
}

ul#second-level-menu > li
{
position: relative;
height: 30px;
background: #999999;
}
ul#second-level-menu > li:hover { background: #CCCCCC; }

ul#top-level-menu
{
list-style: none;
padding: 0;
margin: 0;
}

ul#top-level-menu > li
{
position: relative;
float: left;
height: 30px;
width: 150px;
background: #999999;
}
ul#top-level-menu > li:hover { background: #CCCCCC; }

ul#top-level-menu li:hover > ul
{
/* On hover, display the next level's menu */
display: inline;
}


/* Menu Link Styles */

ul#top-level-menu a /* Apply to all links inside the multi-level menu */
{
font: bold 14px Arial, Helvetica, sans-serif;
color: #FFFFFF;
text-decoration: none;
padding: 0 0 0 10px;

/* Make the link cover the entire list item-container */
display: block;
line-height: 30px;
}

ul#top-level-menu a:hover { color: #000000; }

我有JS(文件名:Menu-Script.js)

document.getElementById("nav01").innerHTML =
"<ul id='top-level-menu'>" +
"<li><a href='index.html'>Home</a>" + // not close li here

"<ul id='second-level-menu'>" +
"<li><a href='index12.html'>Home12</a>" + // not close li here


 "<ul id='third-level-menu'>" +
 "<li><a href='index123.html'>Home123</a></li>" +
 "<li><a href='index124.html'>Home124</a></li>" +
 "</ul></li>" + // close li here

 "<li><a href='index13.html'>Home13</a></li>" +

"</ul></li>"  + // close li here

"<li><a href='customers.html'>Data</a></li>" +
"<li><a href='about.html'>About</a></li>" +
"</ul>"; 


document.getElementById("foot01").innerHTML =
"<p>&copy;  " + new Date().getFullYear() +
" OKay..</p>";

1 个答案:

答案 0 :(得分:0)

这有很多问题,你在无html5文档中使用html5标签。

然而问题是由于您在页脚标记之前加载了js,因此js看不到它。

菜单不一定要在js中使用普通的html。

 <!DOCTYPE html>
 <html>
 <head>
 <link href="site123.css" rel="stylesheet">
 </head>
 <body>

 <nav id="nav01">
     <ul id="top-level-menu">
         <li><a href="index.html">Home</a>
             <ul id="second-level-menu">
                 <li><a href="index12.html">Home12</a>
                     <ul id="third-level-menu">
                         <li><a href="index123.html">Home123</a></li>
                         <li><a href="index124.html">Home124</a></li>
                     </ul>
                 </li>
                 <li><a href="index13.html">Home13</a></li>
             </ul>
         </li>
         <li><a href="customers.html">Data</a></li>
         <li><a href="about.html">About</a></li>
     </ul>
 </nav>


 <div id="main">


 <h1>Welcome to Our Site</h1>
 <h2>Web Site Main Ingredients:</h2>

 <p>Pages (HTML)</p>
 <p>Style (CSS)</p>
 <p>Code (JavaScript)</p>


 <footer id="foot01"></footer>
 </div>
 <script>
     document.getElementById("foot01").innerHTML =
 "<p>&copy;  " + new Date().getFullYear() +
 " OKay..</p>";
 </script>
 </body>
 </html>