HTML Auto-Scalable form table JS implementation _javascript Skills

Source: Internet
Author: User
Tags one table
The following code solves this problem: when the table is loaded, TD width is the original length, will not open TD, and will not affect other TD, click on a line of all cells in the Bank of the largest number of rows in the length of the cell elongation line height. The user experience is very good.
"Benefits"
1. No effect on the forms specified by the developer;
2, easy to use;
3, the defined table style can be arbitrarily customized your style, does not affect your style;
4, the transplant is good, the expansibility is good.
"Disadvantage"
Currently used IE7 test normal, but do not support Firefox, work more busy, no time to correct, I hope that users to correct, I thank you here. ^_^

"Use Method"
1, the Autotablesize.js package file [click here to download the source code] imported into your Web application directory;
2, the introduction of package autotablesize.js, the bottom of the page to join:
<script type= "Text/javascript" src= "Autotablesize.js" ></script>
3, write your script call:
New Autotablesize (); The id attribute of a table is not specified when there is only one table in the DOM object;
New Autotablesize (table); Table: can be either a table id attribute or a Table object;
SOURCE Autotablesize.js
Copy Code code as follows:

/**
* @ version:1.0
* @ Author:xing,xiudong
* @ email:xingxiudong[at]gmail.com
* @ index:http://blog.csdn.net/xxd851116
* @ date:2009.04.01 April Fool's Day
* @ desciption:autotablesize
*/
function autotablesize (table) {
Table = Table | | document.getElementsByTagName ("table") [0];
this.table = typeof (table) = = "String"? document.getElementById ("table"): Table;
This.init ();
}

AutoTableSize.prototype.init = function () {
Autotablesize = this;
var Lastclickrowindex;
var clickcount = 0;
for (var i = 0; i < this.table.rows.length; i++) {
var maxrowheight = 0;
var tds = This.table.rows[i].cells;
if (Tds.length = = 0) continue;
for (var j = 0; J < Tds.length; J + +) {
Maxrowheight = maxrowheight > tds[j].offsetheight? Maxrowheight:tds[j].offsetheight;
var innerdiv = document.createelement ("div");
InnerDiv.style.height = number (this.table.style.fontSize.substring (0, this.table.style.fontsize.length-2)) + 1 + "px" ;
InnerDiv.style.overflow = "hidden";
InnerDiv.style.margin = "0";
InnerDiv.style.padding = "0";
InnerDiv.style.border = "0";
innerdiv.innerhtml = tds[j].innerhtml;

tds[j].innerhtml = "";
Tds[j].appendchild (INNERDIV);
}
This.table.rows[i].maxheight = Maxrowheight;
This.table.rows[i].onmouseover = function () {This.style.backgroundColor = "#DAE9FE";}
This.table.rows[i].onmouseout = function () {This.style.backgroundColor = "#FFF";}
This.table.rows[i].onclick = function () {
if (This.rowindex = = Lastclickrowindex) {
if (clickcount% 2 = 0) {
AUTOTABLESIZE.SHOWTR (This.rowindex);
} else {
AUTOTABLESIZE.HIDETR (This.rowindex);
}
clickcount++;
Return
}
AUTOTABLESIZE.HIDETR (Lastclickrowindex);
AUTOTABLESIZE.SHOWTR (This.rowindex);
Lastclickrowindex = This.rowindex;
clickcount++;
}
}
}
AutoTableSize.prototype.hideTR = function (index) {
if (! Number (index)) return;
TDS = This.table.rows[index].cells;
for (var i = 0; i < tds.length; i++) {
Tds[i].firstchild.style.height = number (this.table.style.fontSize.substring (0, This.table.style.fontsize.length-2 ) + 1 + "px";
}
}
AutoTableSize.prototype.showTR = function (index) {
if (! Number (index)) return;
TDS = This.table.rows[index].cells;
for (var i = 0; i < tds.length; i++) {
Tds[i].firstchild.style.height = this.table.rows[index].maxheight-2 * This.table.getAttribute ("cellpadding");
}
}

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.