我正在写作是因为我有一个将动态类分配给列表的问题。这是因为您可能没有很好地运行子项。我的代码是:
<nav id="menu">
<div class="container">
<div class="fourteen columns" style="width: 765px">
<ul>
<li class="current">
<a href="#storia" >ABOUT US</a>
<ul>
<li><a href="#storia">STORIA</a></li>
<li ><a href="#team" >TEAM</a></li>
</ul>
</li>
<li>
<a href="#fianco">SERVICES</a>
<ul>
<li><a href="#fianco" >COMPETENZA</a></li>
<li><a href="#referenze">REFERENZE</a></li>
</ul>
</li>
</ul>
和 Javascript:
//build dropdown
$("<select />").appendTo("#menu");
// Create default option "Go to..."
$("<option />", {
"selected": "selected",
"value" : "",
"text" : "Go to..."
}).appendTo("nav select");
// Populate dropdowns with the first menu items
$("#menu li a").each(function() {
var el = $(this);
$("<option />", {
"value" : el.attr("href"),
"text" : el.text()
}).appendTo("nav select");
});
//make responsive dropdown menu actually work
$("nav select").change(function() {
window.location = $(this).find("option:selected").val();
});
感谢大家帮助我!