加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

AJAX TAB JQUERY 选项卡 标签

发布时间:2020-12-16 00:52:24 所属栏目:百科 来源:网络整理
导读:AJAX TAB JQUERY 选项卡 标签 演示 js JavaScript Code script $(document).ready( function (){ var Tabs={ 'Tabone' : 'pages/page1.html' , 'Tabtwo' : 'pages/page2.html' , 'Tabthree' : 'pages/page3.html' ,0);"> 'Tabfour' : 'pages/page4.html' } v

AJAX TAB JQUERY 选项卡 标签

演示

js

JavaScript Code
  1. <script>
  2. $(document).ready(function(){
  3. varTabs={
  4. 'Tabone':'pages/page1.html',
  5. 'Tabtwo':'pages/page2.html',
  6. 'Tabthree':'pages/page3.html',0);">'Tabfour':'pages/page4.html'
  7. }
  8. varcolors=['blue','green','red','orange'];
  9. vartopLineColor={
  10. blue:'lightblue',0);">green:'lightgreen',0);">red:'red',0);">orange:'orange'
  11. }
  12. /*LoopingthroughtheTabsobject:*/
  13. varz=0;
  14. $.each(Tabs,function(i,j){
  15. /*Sequentiallycreatingthetabsandassigningacolorfromthearray:*/
  16. vartmp=$('<li><ahref="#"class="tab'+colors[(z++%4)]+'">'+i+'<spanclass="left"/><spanclass="right"/></a></li>');
  17. /*Settingthepagedataforeachhyperlink:*/
  18. tmp.find('a').data('page',j);
  19. /*AddingthetabtotheULcontainer:*/
  20. $('ul.tabContainer').append(tmp);
  21. })
  22. /*Cachingthetabsintoavariableforbetterperformance:*/
  23. varthe_tabs=$('.tab');
  24. the_tabs.click(function(e){
  25. /*"this"pointstotheclickedtabhyperlink:*/
  26. varelement=$(this);
  27. /*Ifitiscurrentlyactive,returnfalseandexit:*/
  28. if(element.find('#overLine').length)returnfalse;
  29. /*Detectingthecolorofthetab(itwasaddedtotheclassattributeintheloopabove):*/
  30. varbg=element.attr('class').replace('tab','');
  31. /*Removingtheline:*/
  32. $('#overLine').remove();
  33. /*CreatinganewlinewithjQuery1.4bypassingasecondparameter:*/
  34. $('<div>',{
  35. id:'overLine',0);">css:{
  36. display:'none',0);">width:element.outerWidth()-2,
  37. background:topLineColor[bg]||'white'
  38. }}).appendTo(element).fadeIn('slow');
  39. /*CheckingwhethertheAJAXfetchedpagehasbeencached:*/
  40. if(!element.data('cache'))
  41. {
  42. /*Ifnocacheispresent,showthegifpreloaderandrunanAJAXrequest:*/
  43. $('#contentHolder').html('<imgsrc="img/ajax_preloader.gif"width="64"height="64"class="preloader"/>');
  44. $.get(element.data('page'),function(msg){
  45. $('#contentHolder').html(msg);
  46. /*Afterpagewasreceived,addittothecacheforthecurrenthyperlink:*/
  47. element.data('cache',msg);
  48. });
  49. else$('#contentHolder').html(element.data('cache'));
  50. e.preventDefault();
  51. /*Emulatingaclickonthefirsttabsothatthecontentareaisnotempty:*/
  52. the_tabs.eq(0).click();
  53. });
  54. </script>

index.html

XML/HTML Code
    <divid="main">
  1. ulclass="tabContainer">
  2. </ul>
  3. divclass="clear"></div>
  4. divid="tabContent">
  5. divid="contentHolder">
  6. div>
  7. div>


原文地址: http://www.freejs.net/article_tabbiaoqian_46.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读