tab£¨Ñ¡Ï£©¼¼ÊõºÜ³£¼û£¬¼´Ê¹¸Õ̤ÈëÇ°¶Ë¿ª·¢µÄͬѧ¶¼»áʹÓÃËüÈ¥Íê³ÉһЩ»ù±¾µÄÈÎÎñ¡£ÕâÀïÌÖÂÛµÄÊÇÒ»ÖÖÃæÏò¶ÔÏóµÄtab£¬ÆäʵÊÇ»»Ò»ÖÖÉè¼Æģʽ À´Éè¼Æ´úÂ룬ÕâÀïÓõ½µÄÊǼòµ¥¹¤³§£¬Õâ¸öTabÀàÌṩºÜ¶à½è¿Ú£¬ÈçonSwitch,switchTo...ÀûÓÃÕâ¸ötab×é¼þ¿ÉÒÔ¶¨ÖÆÐÎʽ¶àÑù»¯µÄ tab¡£
ʹÓ÷½·¨¼òµ¥£¬Ïêϸ²Î¿¼ÈçÏÂdemo£º
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>ÃæÏò¶ÔÏóµÄÑ¡Ï---ÕñÖ®²©ÎÄ</title> <style type="text/css"> *{ margin:0; padding:0;} body{ color:#000;} h1{ text-align:center; line-height:80px; text-shadow:1px 1px 1px #ccc; color:#666;} .tab{ width:606px; margin:0 auto 50px; color:#555;} .tab h2{ overflow:hidden; width:100%; font-size:14px;} .tab h2 a{ float:left; width:200px; line-height:24px; text-align:center; border:1px solid #d5d5d5; cursor:pointer;} .tab h2 a.current{ border:1px solid #d5d5d5; border-width:1px 1px 0; color:#FF3300;} .tab ul{ display:none; border:1px solid #d5d5d5; border-top:0; padding:8px 0;line-height:24px; } .tab ul li{ list-style:inside decimal; margin-left:10px;} #copyright{ width:606px; margin:0 auto;} </style> <script type="text/javascript"> /** * ¹¹Ô캯Êý * @class Tab */ function Tab(){ this.init.apply(this,arguments); } Tab.prototype = { /** * ³õʼ»¯ * @param id{string} tabÈÝÆ÷µÄid * @param config{object} ÅäÖÃÏî * @ÅäÖÃ˵Ã÷:eventType{string} ´¥·¢Ê¼þÀàÐÍ * navTag{string} tabµ¼º½µÄ±êÇ©Ãû navCell{string} tabµ¼º½ÄڵıêÇ©Ãû³Æ content{string} tabÇл»ÄÚÈÝÈÝÆ÷µÄ±êÇ©Ãû³Æ navActiveClass{string} tabÇл»Ê±µ¼º½µÄ¸ßÁÁÑùʽ onSwitch{fn} tabÇл»µÄ»Øµ÷,fnËù´ø²ÎÊýΪobject£¬ÓÐindex¡¢navcell¡¢contentÈý¸öÊôÐÔ * @return void */ init: function(id,config){ var that = this; config = that.config = that.checkInterface(config); that.bindEvent(id,config); }, /** * ¼òдbyid·½·¨ */ $: function(id){ return document.getElementById(id); }, /** * ÑéÖ¤½Ó¿Ú,¹¹½¨ÕýÈ·µÄ²ÎÊýÐÎʽ * @param obj{object} ÅäÖÃÏî * @return object */ checkInterface: function(obj){ return { eventType: obj.type || 'click', navTag: obj.navTag || 'h2', navCell: obj.navCell || 'a', content: obj.content || 'ul', navActiveClass: obj.navActiveClass || 'current', onSwitch: obj.onSwitch || new Function }; }, /** * Ôö¼Óʼþ¼àÌý * @param id{string} tabÈÝÆ÷µÄid * @param config{object} ¼ûÉÏ * @return ʵÀý¶ÔÏó±¾Éí */ bindEvent: function(id,config){ var that = this; var obj = that.obj = that.$(id), navcell = that.navcell = obj.getElementsByTagName(config.navTag)[0].getElementsByTagName(config.navCell), content = that.content = obj.getElementsByTagName(config.content), eventType = 'on' + config.eventType; that.switchTo(0); for(var i=navcell.length;i--;){ navcell[i][eventType] = that.makeCallback(i); } return that; }, /** * ±Õ°ü´æ´¢µ±Ç°Ë÷Òý * @param index{number} Ë÷Òý * @return fn */ makeCallback: function(index){ var that = this; return function(){ that.switchTo(index); } }, /** * tabÇл»µ÷Óõķ½·¨ * @param index{number} Ë÷Òý * @return ʵÀý¶ÔÏó±¾Éí */ switchTo: function(index){ var that = this; for(var i=that.navcell.length;i--;){ that.navcell[i].className = ''; that.content[i].style.display = ''; } that.navcell[index].className = 'current'; that.content[index].style.display = 'block'; var o = { navcell: that.navcell[index], content: that.content[index], index: index }; that.config.onSwitch.call(that,o); return that; } }; </script> </head> <body> <h1>·â×°µÄÑ¡Ï</h1> <div class="tab" id="tab1"> <h2><a>Ñ¡Ïî1</a><a>Ñ¡Ïî2</a><a>Ñ¡Ïî3</a></h2> <ul> <li>Ñ¡Ïî1ÄÚÈÝ</li> <li>Ñ¡Ïî1ÄÚÈÝ</li> <li>Ñ¡Ïî1ÄÚÈÝ</li> <li>Ñ¡Ïî1ÄÚÈÝ</li> </ul> <ul> <li>Ñ¡Ïî2ÄÚÈÝ</li> <li>Ñ¡Ïî2ÄÚÈÝ</li> <li>Ñ¡Ïî2ÄÚÈÝ</li> <li>Ñ¡Ïî2ÄÚÈÝ</li> </ul> <ul> <li>Ñ¡Ïî3ÄÚÈÝ</li> <li>Ñ¡Ïî3ÄÚÈÝ</li> <li>Ñ¡Ïî3ÄÚÈÝ</li> <li>Ñ¡Ïî3ÄÚÈÝ</li> </ul> </div> <div id="copyright"><a href="http://www.cnblogs.com/zhenn/">ÕñÖ®²©ÎÄ</a> °æȨËùÓРתÔØÇë˵Ã÷³ö´¦</div> <script type="text/javascript"> var tab1 = new Tab('tab1',{ eventType: 'click', navTag: 'h2', navCell: 'a', content: 'ul', navActiveClass: 'current', onSwitch: function(o){ alert(o.content.tagName) } }).switchTo(1); </script> </body> </html>
ÍƼöÐÅÏ¢
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- jQuery Tooltips²å¼þ
- jQueryµÄ.bind()¡¢.live()ºÍ.delegate(....
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- Ä㲻ϲ»¶»ðºü£¬µ«ÓÖϲ»¶firebug£¬ÄǾ͸úÎÒÒ»ÆðÀ´ÔÚIEÉÏ....
- ¸ù¾ÝÏÔʾÆ÷·Ö±æÂʵ÷ÕûÒ³ÃæÏÔʾµÄJavascript½Å±¾
- jQuery дµÄ·ÂÐÂÀË΢²© ÏòϹö¶¯Ð§¹û¡¾×ªÔØ¡¿
- ͨÓõÄJqueryÑ¡ÔñÆ÷
- jQuery ½áºÏ Json Ìá½»Êý¾Ýµ½Webservice£¬....
- ×ÔÖÆjQueryÖÇÄÜÌáʾ²å¼þһö
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- js»ñÈ¡srcÖд«µÝµÄ²ÎÊý
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- ÈÃä¯ÀÀÆ÷ÆÁ±ÎµôJavaScriptµÄ³ö´íÌáʾ
- github²»ÄܼÓÔØcss¡¢js½â¾ö°ì·¨
- ÎÒÖªµÀµÄJavaScript -- Éè¼Æģʽ(ÇŽÓ)Ó¦ÓÃÖ® ¨C ....
- 15¸öÖµµÃ¿ª·¢ÈËÔ±¹Ø×¢µÄjQuery¿ª·¢¼¼ÇɺÍÐĵÃ
- dz̸JavascriptÃæÏò¶ÔÏó±à³Ì
- JS¼òµ¥¶¯»·â×°
- JavaScript³õѧÕßӦעÒâµÄÆ߸öϸ½Ú
- jQuery Tooltips²å¼þ
ÆÀÂÛ