0

在我的页面中,我有一些选项卡...但是根据要求,这些选项卡显示在靠近中间的某个位置...因此,选项卡上方的部分加载速度很快,加载该部分需要一些时间其中包含选项卡...

加载主页时,选项卡内的所有页面也都加载了...所以需要一些时间...我该如何避免这种情况?...

我的代码:

<div class="ui-tabs" id="tabs" style="width: 97%;display:none;">
                    <ul class="ui-tabs-nav">
                        <li id="planDetails-tab"><a id="hrefPlanDetailsid" accesskey="p" href="#divPlanDetailsTab" class="planTabHeader">&nbsp;Plan Details</a></li>
                        <li id="testPlan-tab"><a id="hrefTestPlanid" accesskey="t" href="#divTestPlanTab" class="planTabHeader">&nbsp;&nbsp;Test Plan&nbsp;&nbsp;&nbsp;</a></li>                        
                        <li id="serviceArea-tab"><a href="#divServiceAreaTab" accesskey="s" class="planTabHeader">Service Area</a></li>
                        <li id="rates-tab"><a href="#divRatesTab" accesskey="r" class="planTabHeader">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rates&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>
                        <li id="benefits-tab"><a href="#divBenefitsTab" accesskey="b" class="planTabHeader">&nbsp;&nbsp;&nbsp;&nbsp;Benefits&nbsp;&nbsp;&nbsp;</a></li>
                        <li id="network-tab"><a href="#divNetworkEcpTab" accesskey="n" class="planTabHeader">Network ECP</a></li>
                        <li id="historical-tab"><a href="#divHistoricalTab" accesskey="h" class="planTabHeader">&nbsp;&nbsp;Historical&nbsp;&nbsp;&nbsp;</a></li>
                        <li id="directory-tab"><a href="#divDirectoryTab" accesskey="d" class="planTabHeader">&nbsp;&nbsp;&nbsp;Directory&nbsp;&nbsp;</a></li>
                    </ul>

                    <div id="divPlanDetailsTab" style="width: 100%;">
                        <fieldset>
                            <s:include value="PlanDetail.jsp" />
                        </fieldset>
                    </div>
                    <div id="divTestPlanTab" style="width: 100%;">
                        <fieldset>
                            <s:include value="TestPlan.jsp" />
                        </fieldset>
                    </div>                  
                    <div id="divServiceAreaTab"
                        class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"  style="width: 100%;">
                        <fieldset>
                        <s:include value="PlanServiceArea.jsp" />
                        </fieldset>
                    </div>                  

                    <div id="divRatesTab"
                    class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"  style="width: 100%;">
                        <fieldset>
                        <s:include value="Rates.jsp" />
                        </fieldset>
                    </div>

                    <div id="divBenefitsTab" class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"  style="width: 100%;">
                        <fieldset>
                        <s:include value="PlanBenefits.jsp" />
                        </fieldset>
                    </div>

                    <div id="divNetworkEcpTab"
                    class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"  style="width: 100%;">
                        <fieldset>
                        <s:include value="NetworkECP.jsp" />
                        </fieldset>
                    </div>

                    <div id="divHistoricalTab" class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"  style="width: 100%;">
                    <fieldset>
                        <s:include value="PlanHistorical.jsp" />
                        </fieldset>
                    </div>
                    <div id="divDirectoryTab"
                    class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"  style="width: 100%;">
                        <fieldset>
                            <s:include value="ProviderDirectory.jsp" />
                        </fieldset>
                    </div>
            </div>

.js 文件:

$(function() {
            $tabs = $("#tabs").tabs();
            $tabs.css('display','block');

            //Initially hide Test Plan tab
            $('ul li#testPlan-tab').hide();
            $('#hrefTestPlanid').hide();
            $tabs.tabs({
                active : function(event, ui) {
                }
            });
        });
4

1 回答 1

0

只需使用 AJAX 方法使用内容加载:http: //jqueryui.com/tabs/#ajax

这样,您就不会加载大量可能永远不会显示的文本或元素

创建一个目录“ajax”,将选项卡的代码移动到特定文件中并定义如下选项卡:

<ul class="ui-tabs-nav">
    <li id="planDetails-tab"><a href="ajax/divPlanDetailsTab.php" id="hrefPlanDetailsid" accesskey="p" class="planTabHeader">&nbsp;Plan Details</a>
    </li>
    <li id="testPlan-tab"><a href="ajax/divTestPlanTab.php" id="hrefTestPlanid" accesskey="t" class="planTabHeader">&nbsp;&nbsp;Test Plan&nbsp;&nbsp;&nbsp;</a>
    </li>
    ...
</ul>

  <script>
  $(function() {
    $( "#tabs" ).tabs({
      beforeLoad: function( event, ui ) {

          ui.panel.html("Loading in progress...");

          ui.jqXHR.error(function() {
          ui.panel.html(
            "Couldn't load this tab. We'll try to fix this as soon as possible. " +
            "If this wouldn't be a demo." );
        });
      }
    });
  });
  </script>
于 2013-03-26T06:46:11.183 回答