[英]Auto-generated navigational menu for single page website
I want to create an auto-generated navigational menu for a single page website. 我想为单页网站创建一个自动生成的导航菜单。
<!-- html -->
<section id="home">
</section>
<section id="aboutus">
</section>
<section id="contactus">
</section>
<nav id="nav_menu">
</nav>
// jQuery
<script>
$(function() {
$('section').each(function(index) {
$('#nav_menu').append('<a href="'+$(this).hash+'">♦<br /></a>')
});
});
</script>
I'd like to create a diamond for each section in the page, where each diamond will have an anchor to the corresponding page. 我想为页面中的每个部分创建一个菱形,其中每个菱形将具有对应页面的锚点。
The problem is $(this).location.hash shows undefined instead of the anchor of the page. 问题是$(this).location.hash显示为undefined,而不是页面的锚点。 I'm not sure about what should I use in order to get the hash of the section. 我不确定应该使用什么来获取该部分的哈希值。
You are wanting the ID of the section 您需要该部分的ID
$('section').each(function(index) {
$('#nav_menu').append('<a href="#'+this.id+'">♦<br /></a>')
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.