首页 > 代码库 > 兼容性很好的横向选项卡

兼容性很好的横向选项卡

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>风云榜</title><style>body,div,h5,ul,li{margin:0;padding:0;}body{font:12px/1.5 Arial;}li{list-style:none;}a:link,a:visited{color:#333;text-decoration:none;}a:hover{text-decoration:underline;}.tabs {display:inline;float:left;width:270px;}.tabs .tab{position:relative;height:25px;}.tabs .tab ul{top:0px;width:260px;height:28px;overflow:hidden;}.tabs .tab ul li{float:left;cursor:pointer;line-height:26px;padding:0 8px;}.tabs .tab ul li.current{ cursor:pointer; color:#E45E2E;font-weight:700;}.tabs .items{display:none; }.tabs .items a{color:#3A64B0;}.tabs .items li{height:24px;line-height:24px;padding-left:20px;border-bottom:1px solid #EBEBEB;}</style><script>var fgm = { $: function(id) {  return typeof id === "object" ? id : document.getElementById(id); }, $$: function(tagName, oParent) {  return (oParent || document).getElementsByTagName(tagName); }, $$$: function(className, element, tagName) {  var i = 0, aClass = [], reClass = new RegExp("(^|\\s)" + className + "(\\s|$)"), aElement = fgm.$$(tagName || "*", element || document);  for (i = 0; i < aElement.length; i++) reClass.test(aElement[i].className) && aClass.push(aElement[i]);  return aClass; }, index: function(element) {  var aChildren = element.parentNode.children, i;  for(i = 0; i < aChildren.length; i++) if(aChildren[i] === element) return i;  return -1; }, on: function(element, type, handler) {  return element.addEventListener ? element.addEventListener(type, handler, !1) : element.attachEvent("on" + type, handler);  }, bind: function(object, handler) {  return function() {   return handler.apply(object, arguments);  };  }};function Tab(id) { var that = this; this.obj = fgm.$(id); this.oTab = fgm.$$$("tab", this.obj)[0]; this.aTab = fgm.$$("li", this.oTab); this.oSwitch = fgm.$$$("switchBtn", this.oTab)[0]; this.oPrev = fgm.$$("a", this.oSwitch)[0]; this.oNext = fgm.$$("a", this.oSwitch)[1]; this.aItems = fgm.$$$("items", this.obj); this.iNow = 0;   fgm.on(this.oSwitch, "click", fgm.bind(this, this.fnClick)); fgm.on(this.oTab, "mouseover", fgm.bind(this, this.fnMouseOver));}Tab.prototype = { fnMouseOver: function(ev) {  var oEv = ev || event,  oTarget = oEv.target || oEv.srcElement;  oTarget.tagName.toUpperCase() === "LI" && (this.iNow = fgm.index(oTarget));  this.fnSwitch(); }, fnClick: function(ev) {  var oEv = ev || event,  oTarget = oEv.target || oEv.srcElement,  i;  switch(fgm.index(oTarget)) {   case 0:    if(oTarget.className == "prev") {     this.aTab[this.iNow].style.display = "block";     this.iNow--;     };    break;   case 1:    if(oTarget.className == "next") {          for(i = 0; i < this.iNow; i++) this.aTab[i].style.display = "none";     this.iNow++;     };    break;  };  this.aTab[this.iNow].style.display = "block";    this.fnSwitch();  }, fnSwitch: function() {  for(var i = 0; i < this.aTab.length; i++) (this.aTab[i].className = "", this.aItems[i].style.display = "none");   this.aTab[this.iNow].className = "current";  this.aItems[this.iNow].style.display = "block"; }};//应用fgm.on(window, "load", function() { var aItem = fgm.$$$("tabs"), i = 0; for(; i < aItem.length; i++) new Tab(aItem[i]);});</script></head>    <div class="tabs">            <div class="tab">                <ul>                    <li>英语</li>                    <li>留学</li>                </ul>                <span class="switchBtn"></span>            </div>            <div class="items" style="display:block;">            <ul>                <li><a href="http://js.alixixi.com">北京四中网校</a></li>                <li><a href="http://js.alixixi.com">学大教育</a></li>                <li><a href="http://js.alixixi.com">中国统一教育网</a></li>                <li><a href="http://js.alixixi.com">101远程教育网</a></li>                <li><a href="http://js.alixixi.com">巨人教育</a></li>                <li><a href="http://js.alixixi.com">黄冈中学网校</a></li>            </ul>            </div>            <div class="items">            <ul>                <li><a href="http://js.alixixi.com">新东方</a></li>                <li><a href="http://js.alixixi.com">英孚教育</a></li>                <li><a href="http://js.alixixi.com">环球雅思</a></li>                <li><a href="http://js.alixixi.com">韦博国际英语</a></li>                <li><a href="http://js.alixixi.com">华尔街英语</a></li>                <li><a href="http://js.alixixi.com">新航道</a></li>            </ul>            </div>      </div></body></html>

  

兼容性很好的横向选项卡