Example code explanation jquery easyui Dynamic tab page _jquery

Source: Internet
Author: User

The

can easily add Tabs by using JQuery Easyui. You just need to call the ' add ' method.

function AddTab (title, Href,icon) {var tt = $ (' #tabs '); 
    if (Tt.tabs (' exists ', title)) {//If tab already exists, select and Refresh the tab tt.tabs (' select ', title); 
  Refreshtab ({tabtitle:title,url:href}); else {if (href) {var content = ' <iframe scrolling= ' no ' frameborder= ' 0 ' src= ' +href+ ' style= ' width:100%; height:100%; " 
    ></iframe> '; 
    else {var content = ' not implemented '; } tt.tabs (' Add ', {title:title, closable:true, content:content, iconcls:icon| | ') 
  Icon-default '}); }/** * Refresh tab * @cfg *example: {tabtitle: ' tabtitle ', url: ' Refreshurl '} * If the tabtitle is empty, the currently selected Tab * is refreshed by default if the URL is empty , the default is the original URL for reload/function Refreshtab (cfg) {var refresh_tab = cfg.tabtitle?$ (' #tabs '). Tabs (' Gettab ', cfg.tabtitl 
  E): $ (' #tabs '). Tabs (' getselected '); if (Refresh_tab && refresh_tab.find (' iframe '). Length > 0) {var _refresh_ifram = refresh_tab.find (' iframe ') [0 
  ]; var refresh_url = cfg.url?cfg.url:_refresh_ifram.src; 
  _REFRESH_IFRAM.SRC = Refresh_url; 
  _refresh_ifram.contentwindow.location.href=refresh_url;  }

The above code is easy to understand, the code is a comment, there are questions welcome to my message.

Ps:jquery Easyui's Tabs plug-in has two ways to load content on a tab (tab): "HREF remote request" and "content local contents."

The characteristics of the two:

The characteristics of the HREF way to load data:

The loaded page is only loaded with the contents of the BODY element, which is the only HTML fragment of the jquery Ajax request.
When loading a remote URL, there is a mask effect, that is, "wait ..." effect, the user experience is better.
When the load of the page layout is more complex, or more JS script needs to run, the code often need to be cautious, easy to problem, later will be discussed in detail.

Content method to load data features:

More flexible, you can spell the HTML code in the script, and then assign the content attribute to the tab, but this type of writing will make the code legibility worse.
You can assign an iframe to content, and there's nothing you can't do to embed an IFRAME.
The use of IFRAME will cause the client JS repeated loading, waste resources, such as your homepage to refer to Easyui Library, your IFrame also to cite, waste produced.

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.