兩則代碼都很簡單,這裡就不多廢話了,直接上代碼
代碼1,
function ntabs(thisObj,Num) {if(thisObj.className == "active")return; var tabObj = thisObj.parentNode.id; var tabList = document.getElementById(tabObj).getElementsByTagName("li"); for(i=0; i <tabList.length; i++) {if (i == Num) {thisObj.className = "active"; document.getElementById(tabObj+"_cont"+i).style.display = "block"; } else{ tabList[i].className = "normal"; document.getElementById(tabObj+"_cont"+i).style.display = "none"; } } }
代碼2,
$(document).ready(function(){ var $tab_li = $('.tab ul li'); $tab_li.hover(function(){ $(this).addClass('selected').siblings().removeClass('selected'); var index = $tab_li.index(this); $('div.tab_box > div').eq(index).show().siblings().hide(); }); });