Href and content attributes of easyui tabs

Source: Internet
Author: User

As we all know, jquery easyui's tabs plug-in can load content on a tab in two ways: "href remote request" and "content local content ", this article briefly analyzes and considers the advantages and disadvantages of the two methods.

Features: href:
  1. Only the content inside the body element of the loaded page is loaded. That is, jquery's Ajax request only contains HTML fragments.
  2. When loading a remote URL, there is a mask effect, that is, "waiting ......" Results: better user experience.
  3. When the page layout to be loaded is complex, or a large number of JS scripts need to be run, the encoding usually requires caution, which is prone to problems and will be discussed in detail later.
Data Loading using content:
  1. Flexible. You can spell the HTML code in the script and assign the content attribute to the tab. However, this write method will make the code easier to understand.
  2. You can assign an IFRAME to the content and embed an IFRAME.
  3. Using IFRAME will cause repeated loading of client JS and waste of resources. For example, if you want to reference the easyui library on your homepage, your IFRAME will also be referenced.
Summary:

According to the above analysis, the method of using content is more concise, and IFRAME can be introduced to deal with everything. The disadvantages are also obvious. If the system is more complex, it will cause a great waste of resources, only applicable to relatively simple page systems;

The href method requires a little higher encoding capability. It is difficult to handle HTML fragments if you do not pay attention to them. However, if you are skilled, the href method is the best choice.

Href FAQ: 1. href only loads HTML fragments of the target URL

This feature is determined by the Ajax request processing mechanism encapsulated by jquery. Therefore, tags such as HTML, Head, and body do not need to be included in the target URL page. Even if these elements exist, it will also be ignored, so no script in the head label will be introduced or executed.

2. Brief page chaos:

When pages with href links are complex, easyui usually requires a long process to render them. At this time, the HTML fragments that are loaded have no layout, and the page will automatically be fine later, at this time, easyui has completed its rendering. To avoid this chaotic process, we have to rely on the basic plug-in of easyui-parser ).

Parser has an oncomplete event, which is triggered when easyui finishes rendering the page. The idea is clear: Use a div to mask HTML fragments that are loaded, in the oncomplete event, let this Div fade out. At this time, the rendered HTML fragment will be able to take a bath for the beauty, and at the same time, it will have a waiting effect, killing two birds with one stone. In this case, we need to do two things:

First, place a div for the mask in the HTML fragment to be loaded:

<div id="loading" style="position: absolute; z-index: 1000; top: 0px; left: 0px; width: 100%; height: 100%; background: #DDDDDB; text-align: center; padding-top: 20%;"></div>

 

The second is to process related events at the end of the loaded HTML snippet:
function show(){       $("#loading").fadeOut("normal", function(){          $(this).remove();      });  }       var delayTime;   $.parser.onComplete = function(){       if(delayTime)           clearTimeout(delayTime);      delayTime = setTimeout(show,500);   } 

 

Note that if the oncomplete event is used on multiple tab pages, the defined items will overwrite the previously defined ones. In fact, the oncomplete event is called every time easyui rendering is complete. Therefore, every time a tab page containing the easyui control is opened, the oncomplete event is called. 3.The easyui component-related script of the HTML segment inexplicably reports an error:

In fact, this phenomenon is the same as the reason for the first phenomenon. It takes some time for easyui to complete HTML fragment rendering. The more complicated the page, the longer the time consumption, at this time, it is difficult to avoid calling some plug-ins of easyui in HTML scripts, such as DataGrid. At this time, an error will be reported. The solution is the same as above. Put these scripts in the oncomplete event for processing, this ensures that the rendering will not be executed before the rendering is complete.

4. the prompt information for Form Verification in the window will be in disorder:

This phenomenon should be a bug of the plug-in itself. These special things are not taken into account in location calculation. The solution can be opportunistic. After opening the window, let the input that does not conform to the verification form get the focus.

5. Two or multiple remote data loading problems:

The official website has already indicated that this bug has been fixed in version 1.2.5, but many people have responded that remote data may be loaded twice, even in version 1.2.6, if you have encountered such a situation, perform the following checks:

  • Whether the data returned from the remote data contains a style such as "easyui-Tabs" or "class =" easyui-DataGrid ". If yes, easyui automatically renders HTML fragments after obtaining them. At this time, a request has been made to the remote data source;
  • Do you want to use JavaScript to go $ ('# tabsid'). tabs ({...}); Or $ ('# tabsid'). DataGrid ({...}); Binding events or setting properties is actually equivalent to rendering the corresponding control again and then requesting remote data again.

Why? You can see the source code:

$. FN. tabs = function (options, Param) {If (typeof Options = 'string') {// The branch of this place is clear, only when options is a string, the method provided by the control. Return $. FN. Tabs. Methods [Options] (This, Param) ;}// if options is not a string, directly construct the control and inxing rendering. Options = options | {}; return this. each (function () {var state = $. data (this, 'tabs'); var opts; If (state) {opts = $. extend (state. options, options); State. options = opts;} else {$. data (this, 'tabs', {options: $. extend ({}, $. FN. tabs. defaults, $. FN. tabs. parseoptions (this), options), tabs: wraptabs (this), selecthis: []}) ;}buildbutton (this); setproperties (this); setsize (this ); initselecttab (this );});};

 

When writing code, please note that this method is used when there is a ready-made control method. If you directly input an object, all controls will be re-constructed, most of the loading problems of tabs occur.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.