請看下面的代碼吧,比較簡單。
- <html>
- <head>
- <title>一個TAB頁的簡單JS實作</title>
- <style type="text/css">
- #div0{
- width:300px;
- margin:0 auto;
- }
- #div1{
- border:1px solid blue;
- border-bottom:0px solid blue;
- float:left;
- }
- #div2{
- border-right:1px solid blue;
- border-top:1px solid blue;
- float:left;
- }
- #div3{
- border:1px solid blue;
- clear:left;
- }
- #div4{
- border:1px solid blue;
- clear:left;
- }
- </style>
- <script language="javascript">
- window.onload=function(){
- document.getElementById("div1").style.backgroundColor="yellow";
- document.getElementById("div4").style.display="none";
- }
- function foo(){
- document.getElementById("div1").style.backgroundColor="yellow";
- document.getElementById("div2").style.backgroundColor="";
- document.getElementById("div3").style.display="none";
- document.getElementById("div4").style.display="block";
- }
- function bar(){
- document.getElementById("div1").style.backgroundColor="";
- document.getElementById("div2").style.backgroundColor="yellow";
- document.getElementById("div3").style.display="block";
- document.getElementById("div4").style.display="none";
- }
- </script>
- </head>
- <body>
- <div id="div0">
- <div id="div1" onmouseover="foo()">Hello</div>
- <div id="div2" onmouseover="bar()">world</div>
- <div id="div3">Jason周五能中500萬</div>
- <div id="div4">Jason有個好老婆</div>
- </div>
- </body>
- </html>