html如何点击菜单之后页面的内容会改变

html如何点击菜单之后页面的内容会改变,第1张

可以使用iframe,iframe内部是另外一个页面,在点击菜单的时候动态改变iframe的地址。

可以使用页面路由,一般在vue,layui等框架可以使用路由切换页面内容显示。

还有就是可以使用自定义方法,在点击菜单的时候,更改页面当中的html,如:"document.getElementById('content').innerHTML='页面内容2'"。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

<title>无标题文档</title>

<style>

.main{ width:800pxheight:400pxborder:1px solid #999999border-bottom:none}

.top,.foot{ width:800pxheight:30pxborder-bottom:1px solid #999999}

.center{ width:800pxheight:339px}

.left{ width:200pxfloat:left}

.right{ width:600pxfloat:lefttext-align:centerheight:330px}

ul li{ list-style:noneborder:1px solid #999999margin-top:2px}

</style>

<script>

function showDiv(divid,rows,num){

for(i=1i<=rowsi++){

document.getElementById(divid+i).style.display="none"

}

document.getElementById(divid+num).style.display=""

}

</script>

</head>

<body>

<div class="main">

<div class="top">这里是头</div>

<div class="center">

<div class="left">

<ul>

<li onclick="showDiv('right_','4','1')">左边一</li>

<li onclick="showDiv('right_','4','2')">左边二</li>

<li onclick="showDiv('right_','4','3')">左边三</li>

<li onclick="showDiv('right_','4','4')">左边四</li>

</ul>

</div>

<div class="right" id="right_1" style="display:">右边一</div>

<div class="right" id="right_2" style="display:none">右边二</div>

<div class="right" id="right_3" style="display:none">右边三</div>

<div class="right" id="right_4" style="display:none">右边四</div>

</div>

<div class="foot">这里是尾</div>

</div>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7024332.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-31
下一篇 2023-03-31

发表评论

登录后才能评论

评论列表(0条)

保存