时间:2021-07-01 10:21:17 帮助过:24人阅读
两则代码都很简单,这里就不多废话了,直接上代码
代码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(); }); });