|

楼主 |
发表于 2022-3-30 23:31:02
|
显示全部楼层
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>top栏切换</title>
- <style>
- #main{
- position:relative;
- width:600px;
- height:500px;
- background-color:gray;
- margin:0 auto;
- }
- ul{
- display:flex;
- height:50px;
- background-color:green;
- }
- ul li{
- list-style:none;
- margin-left:40px;
- background-color:red;
- text-align:center;
- line-height:40px;
- cursor:pointer;
- }
- ul li:hover{
- background-color:yellow;
- color:gray;
- }
- .one{
- position:absolute;
- top:50px;
- left:0;
- width:600px;
- height:500px;
- background-color:brown;
- }
- .two{
- position:absolute;
- top:50px;
- left:0;
- width:600px;
- height:500px;
- background-color:#FFC0CB;
- }
- .three{
- position:absolute;
- top:50px;
- left:0;
- width:600px;
- height:500px;
- background-color:deeppink;
- }
- .four{
- position:absolute;
- top:50px;
- left:0;
- width:600px;
- height:500px;
- background-color:#808080;
- }
- p{
- width:300px;
- height:300px;
- margin-top:100px;
- margin-left:200px;
- text-align:center;
- line-height:300px;
- background-color:gray;
- }
- </style>
- </head>
- <body>
- <div id="main">
- <ul>
- <li>商品生源地</li>
- <li>商品价格</li>
- <li>商品类型</li>
- <li>商品功能</li>
- </ul>
- <div class="one"><p>来自法国</p></div>
- <div class="two"><p>1999元</p></div>
- <div class="three"><p>手机类</p></div>
- <div class="four"><p>打电话</p></div>
- </div>
- <script>
- var div=document.getElementById('main').getElementsByTagName('div');
- var li=document.getElementsByTagName('ul').getElementsByTagName('li');
- for( var i=0;i<div.length;i++){
- li[i].onclick=function(){
- div[i].style.z-index=1;//为何这里出错;
- }
- }
- </script>
- </body>
- </html>
复制代码
这回还真碰到了这问题了 |
|