1.html代码 复制代码 代码如下: 标题一 标题二 标题三 标题四 div> 内容一 内容二 内容三 内容四 2 .js部分 复制代码 代码如下: <BR>var tab = document.getElementById("tab").getElementsByTagName("h2"); <BR>function swap(n) { <BR>return function() { <BR>for(var i=0; i<tab.length; i++) { <BR>document.getElementById("tabcon" + i).style.display = "none"; <BR>document.getElementById("tab" + i).className = ""; <BR>} <BR>document.getElementById("tabcon" + n).style.display = "block"; <BR>document.getElementById("tab" + n).className = "focus"; <BR>} <BR>} <br><br>for(var i=0; i<tab.length; i++) { <BR>tab[i].setAttribute("id", "tab" + i); <BR>if(window.addEventListener) { <BR>tab[i].addEventListener("mouseover", swap(i), false); <BR>} else if(window.attachEvent) { <BR>tab[i].attachEvent("onmouseover", swap(i)); <BR>} <BR>} <br><br>var tabcon = document.getElementById("tabcon").getElementsByTagName("dd"); <BR>for(i=0; i<tabcon.length; i++) { <BR>tabcon[i].setAttribute("id", "tabcon" + i); <BR>} <br><br>if(document.createEvent) { <BR>var evObj = document.createEvent('MouseEvents'); <BR>evObj.initEvent( 'mouseover', true, false); <BR>tab[0].dispatchEvent(evObj); <BR>} else if( document.createEventObject) { <BR>tab[0].fireEvent('onmouseover'); <BR>} <BR>