jquery实现的tab切换

模板网 2014-10-24

 

1、jQuery能够使用户的html页保持代码和html内容分离,也就是说,不用再在html里面插入一堆js来调用命令了,只需定义id即可。下面跟大家分享一个jquery的tab切换

  

2、如何使用

 

调用jquery文件

 

<script type="text/javascript" src="jquery.js"></script> 

 

jquery实现tab效果

 

<script>

$(function(){

$("div [id^='tabcc_']").each(

  function(i,ob){

  $(ob).find('a').bind

  ('mouseover',function(){

   $(ob).find('a').removeClass('on');

   $(this).addClass('on');

   var cid=$(this).attr('cid');

   $(ob).siblings('div').hide();

   $(ob).siblings("div[id='courseList_"+cid+"']").show();

  });

});

})

</script>

 

2、关于tab的html结构

 

<div class="manage">

   <div class="manage_title" id="tabcc_0">

       <a href="/opencourse/501/index.htm"  cid="501" class='on'>战略管理</a> 

       <a href="/opencourse/502/index.htm"  cid="502" >市场营销</a> 

       <a href="/opencourse/505/index.htm"  cid="503" >采购管理</a> 

    </div>      

     <div class="manage_txt" id="courseList_501" style="display:block; height:100px; padding:20px;">

     789

     </div>

    <div class="manage_txt" id="courseList_502" style="display:none; height:100px; padding:20px; ">

     456

    </div>

    <div class="manage_txt" id="courseList_503" style="display:none; height:100px; padding:20px; ">

     123

    </div>

</div>

这个tab切换可以一个页面多个使用,适用于不同结构的tab切换

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html;charset=gb2312&quot; /&gt;
&lt;title&gt;&lt;/title&gt;
&lt;script src=&quot;http://libs.baidu.com/jquery/1.9.0/jquery.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
$(function(){
$(&quot;div [id^=&#039;tabcc_&#039;]&quot;).each(
  function(i,ob){
  $(ob).find(&#039;a&#039;).bind
  (&#039;mouseover&#039;,function(){
   $(ob).find(&#039;a&#039;).removeClass(&#039;on&#039;);
   $(this).addClass(&#039;on&#039;);
   var cid=$(this).attr(&#039;cid&#039;);
   $(ob).siblings(&#039;div&#039;).hide();
   $(ob).siblings(&quot;div[id=&#039;courseList_&quot;+cid+&quot;&#039;]&quot;).show();
  });
});
})
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;manage&quot;&gt;
  &lt;div class=&quot;manage_title&quot; id=&quot;tabcc_0&quot;&gt; &lt;a href=&quot;/opencourse/501/index.htm&quot;  cid=&quot;501&quot; class=&#039;on&#039;&gt;战略管理&lt;/a&gt; &lt;a href=&quot;/opencourse/502/index.htm&quot;  cid=&quot;502&quot; &gt;市场营销&lt;/a&gt; &lt;a href=&quot;/opencourse/505/index.htm&quot;  cid=&quot;503&quot; &gt;采购管理&lt;/a&gt; &lt;/div&gt;
  &lt;div class=&quot;manage_txt&quot; id=&quot;courseList_501&quot; style=&quot;display:block; height:100px; padding:20px;&quot;&gt; 789 &lt;/div&gt;
  &lt;div class=&quot;manage_txt&quot; id=&quot;courseList_502&quot; style=&quot;display:none; height:100px; padding:20px; &quot;&gt; 456 &lt;/div&gt;
  &lt;div class=&quot;manage_txt&quot; id=&quot;courseList_503&quot; style=&quot;display:none; height:100px; padding:20px; &quot;&gt; 123 &lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

相关文章

  1. 从腾讯网提取的判断手机端访问跳转代码

    从腾讯网提取的判断手机端访问跳转代码,使用了一个正则表达式来判断浏览器的navigator.userAgent标志,来确认访问终端,从而做出相应的操作。 代码简单,注释详细,容易理解。 复制代码 代码如下: script type=text/javascript if(/Android|Windows Phone|w

  2. 离线宝中提取的验证电话号码的函数

    从百度离线宝中提取的验证电话号码的函数,只检查输入的内容是否是11位或12为数字,不是非常完美,但是代码中还是有值得学习的地方。 函数:phone(e){} 参数:e //要验证的号码 返回值:正确返回true,错误弹出提示框并返回false。 效果图:

  3. JS 文本框默认提示信息点击清空

    JS 文本框默认提示信息点击清空,关键的代码。 复制代码 代码如下: onfocus=if(this.value==this.defaultValue){this.value=;}; onblur=if(this.value==){this.value=this.defaultValue;} type=text 效果截图:

  4. JS判断手机号码座机号码函数

    JS判断手机号码座机号码函数,可以准确判断手机和座机号码。 复制代码 代码如下: function Tel(num){ var partten = /^(1[3,4,5,8]\d{9}|01[3,4,5,8]\d{9}|010[1-9]{1,2}\d{6}|02[0-9][1-9]{1,2}\d{6}|0[1-9]{2}[0-9][1-9]{1,2}\d{6})$/; if(partten.test(nu

  5. 移动端全屏滚动插件 zepto.fullpage.js

    zepto.fullpage 是专注于移动端的 fullPag e.js ,依赖 Ze pto 。 下载地址: https://github.com/yanhaijing/zepto.fullpage 功能概述 可实现移动端的单页滚动效果,可自定义参数,提供回调接口,和公开接口。 兼容性 Ios4+ Andriod2.3+(未全部覆盖) 快速

随机推荐

  1. 从腾讯网提取的判断手机端访问跳转代码

    从腾讯网提取的判断手机端访问跳转代码,使用了一个正则表达式来判断浏览器的navigator.userAgent标志,来确认访问终端,从而做出相应的操作。 代码简单,注释详细,容易理解。 复制代码 代码如下: script type=text/javascript if(/Android|Windows Phone|w

  2. 离线宝中提取的验证电话号码的函数

    从百度离线宝中提取的验证电话号码的函数,只检查输入的内容是否是11位或12为数字,不是非常完美,但是代码中还是有值得学习的地方。 函数:phone(e){} 参数:e //要验证的号码 返回值:正确返回true,错误弹出提示框并返回false。 效果图:

  3. JS 文本框默认提示信息点击清空

    JS 文本框默认提示信息点击清空,关键的代码。 复制代码 代码如下: onfocus=if(this.value==this.defaultValue){this.value=;}; onblur=if(this.value==){this.value=this.defaultValue;} type=text 效果截图:

  4. JS判断手机号码座机号码函数

    JS判断手机号码座机号码函数,可以准确判断手机和座机号码。 复制代码 代码如下: function Tel(num){ var partten = /^(1[3,4,5,8]\d{9}|01[3,4,5,8]\d{9}|010[1-9]{1,2}\d{6}|02[0-9][1-9]{1,2}\d{6}|0[1-9]{2}[0-9][1-9]{1,2}\d{6})$/; if(partten.test(nu

  5. 移动端全屏滚动插件 zepto.fullpage.js

    zepto.fullpage 是专注于移动端的 fullPag e.js ,依赖 Ze pto 。 下载地址: https://github.com/yanhaijing/zepto.fullpage 功能概述 可实现移动端的单页滚动效果,可自定义参数,提供回调接口,和公开接口。 兼容性 Ios4+ Andriod2.3+(未全部覆盖) 快速