<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style type="text/css"> *{ margin: 0px auto; padding: 0px; } #dd{ width: 320px; height: 40px; } .nkk{ width: 80px; height: 40px; text-align: center; line-height: 40px; vertical-align: middle; float: left; } .ijj{ width: 320px; height: 300px; } </style> </head> <body> <div id="dd"> <div class="nkk" style="background: red" onClick="Ca(‘uu‘)">军事</div> <div class="nkk" style="background: green;" onClick="Ca(‘uk‘)">新闻</div> <div class="nkk" style="background: blue;" onClick="Ca(‘un‘)">理论</div> </div> <div class="ijj" id="uu" style="background: red"></div> <div class="ijj" id="uk" style="background: green;display: none"></div> <div class="ijj" id="un" style="background: blue;display: none"></div> </body> <script type="text/javascript"> function Ca(a) { var pp = document.getElementById(a) var div = document.getElementsByClassName("ijj") for(i=0;i<div.length;i++) { div[i].style.display= "none"; } pp.style.display= "block"; } </script> </html>
效果图