(function(){ var tit = $("#tab a"), con = $("#tcontent>div"), cur = 'cur'; tit.mousemove(function(){ var index = tit.index(this); $(this).addClass('cur').siblings().removeClass('cur'); con.eq(index).show().siblings().hide(); }); })();
原生js的tab切换
var test = document.getElementById("testbtn"), li = test.getElementsByTagName("span"), testul = document.getElementById("test"), lis = testul.getElementsByTagName("li"), exeFun = function(num){ for (var i = 0,len = li.length;i<len;i++) { if(num == i){ li[i].className = "cur"; lis[i].style.display = "block" }else{ li[i].className = ""; lis[i].style.display = "none" } }; }; for(var i=0,len = li.length;i<len;i++){ li[i].onclick = function(num){ return function(){ console.log(num); exeFun(num); } }(i); }
function clicktabs(tit_id,box_id,cur){ var g_tags=$(tit_id), g_conts=$(box_id), g_current=cur; g_tags.live('mouseover',function(){ var g_index=g_tags.index(this); $(this).addClass(g_current).siblings().removeClass(g_current); g_conts.eq(g_index).show().siblings().hide(); }) } clicktabs("#tab>strong","#reg>div","cur");
$('.tab').click(function(){ var index = $('.tab').index(this), //第一次点击的li的收银纸 ele = $(this).find('.ind'); $('.tab').each(function(i){ if(i != index){ $(this).find('.ind').hide(); } }); if(ele.is(':hidden')){ ele.show(); }else{ ele.hide(); } });