答案 0 :(得分:0)
jQuery(document).ready(function() {
jQuery("<select />").appendTo("#horizontal_nav");
jQuery("<option />", {
"selected": "selected",
"value": ""
}).appendTo("#horizontal_nav select");
jQuery("#horizontal_nav a").each(function() {
var el = jQuery(this);
jQuery("<option />", {
"value": el.attr("href"),
"text": el.text(),
"data-filter": el.attr('data-filter')//add it here
}).appendTo("#horizontal_nav select")
});
jQuery("#horizontal_nav select").change(function() {
window.location = jQuery(this).find("option:selected").val()
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="horizontal_nav">
<ul class="sub-menu">
<li><a href="http://localhost.local/site/horizontal-nav/" data-filter=".term-3"><span><strong>Horizontal Nav</strong></span></a>
</li>
<li><a href="http://localhost.local/site/full-width/" data-filter=".term-4"><span><strong>Full Width</strong></span></a>
</li>
<li><a href="http://localhost.local/site/blog/" data-filter=".term-3"><span><strong>Blog</strong></span></a>
</li>
<li><a href="http://localhost.local/site/cart/" data-filter=".term-4"><span><strong>Cart</strong></span></a>
</li>
<li><a href="http://localhost.local/site/checkout/" data-filter=".term-5"><span><strong>Checkout</strong></span></a>
</li>
<li><a href="http://localhost.local/site/features/" data-filter=".term-5"><span><strong>Features</strong></span></a>
</li>
</ul>
</div>
添加.attr()
名称data-filter
,然后附加ul的数据过滤器