请问前端大神,html如何引入另一个html,写了一个导航栏想在多个页面中如何重复使用?

写了一个头部导航栏的html 
想在多个html页面中引用,请问怎么操作? 
网上找了用<iframe>标签 实际效果并不好 , 导航栏中按钮下拉菜单无法完全显示 
请问大牛们平时开发中怎么处理这个的

如图 :

https://img2.mukewang.com/5bfa5df00001d34e05920217.jpg

陪伴而非守候
浏览 4593回答 1
1回答

幕布斯7119047

可以使用html的import这个功能通过声明&nbsp;<link rel="import">&nbsp;来在页面中包含一个导入具体可以看教程可以向下面这样使用warning.html<div class="warning">&nbsp; <style scoped>&nbsp; &nbsp; h3 {&nbsp; &nbsp; &nbsp; color: red;&nbsp; &nbsp; }&nbsp; </style>&nbsp; <h3>Warning!</h3>&nbsp; <p>This page is under construction</p></div><div class="outdated">&nbsp; <h3>Heads up!</h3>&nbsp; <p>This content may be out of date</p></div>导入<head>&nbsp; <link rel="import" href="warnings.html"></head><body>&nbsp; ...&nbsp; <script>&nbsp; &nbsp; var link = document.querySelector('link[rel="import"]');&nbsp; &nbsp; var content = link.import;&nbsp; &nbsp; // 从 warning.html 的文档中获取 DOM。&nbsp; &nbsp; var el = content.querySelector('.warning');&nbsp; &nbsp; document.body.appendChild(el.cloneNode(true));&nbsp; </script></body>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript