需求:頂部導航欄、底部版權固定,點擊導航/二級菜單切換中間內容區。
<header>固定導航</header>
<nav id="tabs">
<button data-tab="home" class="active">首頁</button>
<button data-tab="about">關於</button>
</nav>
<main>
<section id="home" class="tab-panel active">首頁內容</section>
<section id="about" class="tab-panel">關於內容</section>
</main>
<footer>版權</footer>
<style>
.tab-panel { display:none; } .tab-panel.active { display:block; }
</style>
<script>
document.querySelectorAll('#tabs button').forEach(btn => btn.onclick = () => {
document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active'));
document.querySelectorAll('#tabs button').forEach(b => b.classList.remove('active'));
document.getElementById(btn.dataset.tab).classList.add('active');
btn.classList.add('active');
});
</script>
<header>、<router-view>、<footer>。<router-link> 切換。<iframe src="page1.html" name="content"> + 導航 target="content"。缺點:跨域受限、SEO 差、滾動條巢狀、通訊複雜。