带有jQuery核心的简单选项卡(不是jqueryui)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有jQuery核心的简单选项卡(不是jqueryui)相关的知识,希望对你有一定的参考价值。
Sometimes I want simple tabs without all the packaging of jQuery UI with a theme. This does the job with just jQuery 1.2.6, and should work with later versions.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Simple jQuery Tabs</title> <script src="js/jquery-1.2.6.min.js" type='text/javascript'></script> <script type="text/javascript"> jQuery( function($) { $('.simple-tabs').each( function() { var container = $(this); container.find('> ul li a').click( function () { $(this).parent().addClass( 'selected-tab' ).siblings().removeClass( 'selected-tab' ); container.find('.tab-panel').hide().filter(this.hash).show(); return false; }).eq(0).click(); }); }); </script> <style type="text/css"> .simple-tabs ul { /*resets*/margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.3; text-decoration: none; font-size: 100%; list-style: none; float: left; position: relative; border-right: 1px solid #ddd; bottom: -1px; } .simple-tabs li { /*resets*/margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.3; text-decoration: none; font-size: 100%; list-style: none; float: left; border: 1px solid #ddd; border-right: none; } .simple-tabs li a { /*resets*/margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.3; text-decoration: none; font-size: 100%; list-style: none; float: left; text-decoration: none; padding: .5em 1.7em; color: #555555; background: #e6e6e6; } .simple-tabs li a:hover { background: #dadada; color: #212121; } .simple-tabs li.selected-tab { border-bottom-color: #fff; } .simple-tabs li.selected-tab a, .simple-tabs li.selected-tab a:hover { background: #fff; } .tab-panel { clear:left; border: 1px solid #d3d3d3; background: #ffffff; color: #222222; padding: 1.5em 1.7em; } </style> </head> <body> <h1>Simple Tabs with jQuery (not jQuery UI)</h1> <div id="tab-set-1" class="simple-tabs"> <ul> <li><a href="#tab-1-1" title="">Tab 1</a></li> <li><a href="#tab-1-2" title="">Tab 2</a></li> </ul> <div id="tab-1-1" class="tab-panel"> <h2>Tab 1 panel</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> </div> <div id="tab-1-2" class="tab-panel"> <h2>Tab 2 panel</h2> <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p> </div> </div> <div id="tab-set-2" class="simple-tabs"> <ul> <li><a href="#tab-2-a" title="">Tab A</a></li> <li><a href="#tab-2-b" title="">Tab B</a></li> <li><a href="#tab-2-c" title="">Tab C</a></li> </ul> <div id="tab-2-a" class="tab-panel"> <h2>Tab A panel</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> </div> <div id="tab-2-b" class="tab-panel"> <h2>Tab B panel</h2> <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p> </div> <div id="tab-2-c" class="tab-panel"> <h2>Tab C panel</h2> <p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </p> </div> </div> </body> </html>
以上是关于带有jQuery核心的简单选项卡(不是jqueryui)的主要内容,如果未能解决你的问题,请参考以下文章
jQuery Validation,在提交时显示有效/无效的表单选项卡