重写html,实现内嵌三个本地网页,和三个按键切换功能
时间: 2024-04-14 10:28:45 浏览: 16
```html
<!DOCTYPE html>
<html>
<head>
<title>内嵌网页切换</title>
<style>
/* 样式用于隐藏除当前页面外的其他页面 */
.page {
display: none;
}
.active {
display: block;
}
</style>
</head>
<body>
<button onclick="showPage(1)">页面1</button>
<button onclick="showPage(2)">页面2</button>
<button onclick="showPage(3)">页面3</button>
<div class="page" id="page1">
<iframe src="page1.html" width="100%" height="500"></iframe>
</div>
<div class="page" id="page2">
<iframe src="page2.html" width="100%" height="500"></iframe>
</div>
<div class="page" id="page3">
<iframe src="page3.html" width="100%" height="500"></iframe>
</div>
<script>
function showPage(pageNumber) {
// 隐藏所有页面
var pages = document.getElementsByClassName('page');
for (var i = 0; i < pages.length; i++) {
pages[i].classList.remove('active');
}
// 显示当前页面
var currentPage = document.getElementById('page' + pageNumber);
currentPage.classList.add('active');
}
</script>
</body>
</html>
```
请确保将 `src` 属性的值更改为你本地网页的路径。这样,当点击按钮时,对应的本地网页将在 `<iframe>` 中加载,并且其他的本地网页将被隐藏。注意,这里的示例假设页面1对应的本地网页是 `page1.html`,页面2对应的本地网页是 `page2.html`,页面3对应的本地网页是 `page3.html`。你需要根据实际情况进行修改。
希望这次能满足你的需求。如果还有其他问题,请随时提问。