Example code _ jQuery

Source: Internet
Author: User
JQuery implements the instance code with fixed table header effects. For more information, see section 1. Create a js file jQuery_FixedTableHead.js.

The content is as follows:

The Code is as follows:


JQuery. fn. CloneTableHeader = function (tableId, tableParentDivId ){

Var obj = document. getElementById ("tableHeaderDiv" + tableId );

If (obj ){

JQuery (obj). remove ();

}

Var browserName = navigator. appName;

Var ver = navigator. appVersion;

Var browserVersion = parseFloat (ver. substring (ver. indexOf ("MSIE") + 5, ver. lastIndexOf ("Windows ")));

Var content = document. getElementById (tableParentDivId );

Var scrollWidth = content. offsetWidth-content. clientWidth;

Var tableOrg = jQuery ("#" + tableId)

Var table = tableOrg. clone ();

Table. attr ("id", "cloneTable ");

Var tableClone = jQuery (tableOrg). find ("tr"). each (function (){

});

Var tableHeader = jQuery (tableOrg). find ("thead ");

Var tableHeaderHeight = tableHeader. height ();

TableHeader. hide ();

Var colsWidths = jQuery (tableOrg). find ("tbody tr: first td"). map (function (){

Return jQuery (this). width ();

});

Var tableCloneCols = jQuery (table). find ("thead tr: first td ")

If (colsWidths. size ()> 0 ){

For (I = 0; I <tableCloneCols. size (); I ++ ){

If (I = tableCloneCols. size ()-1 ){

If (browserVersion = 8.0)

TableCloneCols. eq (I). width (colsWidths [I] + scrollWidth );

Else

TableCloneCols. eq (I). width (colsWidths [I]);

} Else {

TableCloneCols. eq (I). width (colsWidths [I]);

}

}

}

Var headerDiv = document. createElement ("p ");

HeaderDiv. appendChild (table [0]);

JQuery(headerDiv).css ("height", tableHeaderHeight );

JQuery(headerDiv).css ("overflow", "hidden ");

JQuery(headerDiv).css ("z-index", "20 ");

JQuery(headerDiv).css ("width", "100% ");

JQuery (headerDiv). attr ("id", "tableHeaderDiv" + tableId );

JQuery (headerDiv). insertBefore (tableOrg. parent ());

}

Ii. Html instance files

The content is as follows:

The Code is as follows:


Qubernet@163.com _ jQuery to achieve the fixed effect of the header (quite good !!!)

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.