AJAX TAB JQUERY 选项卡 标签

前端之家收集整理的这篇文章主要介绍了AJAX TAB JQUERY 选项卡 标签前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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 原文链接:https://www.f2er.com/ajax/165765.html

猜你在找的Ajax相关文章