一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

HTML 自動伸縮的表格Table js實(shí)現(xiàn)

下面的代碼解決了這個問題:當(dāng)表格被載入的時候,TD的寬度是原定的長度,不會撐開TD,也不會影響其他TD,點(diǎn)擊某行會按照本行所有單元格中行數(shù)最多的單元格的長度伸長行高。用戶體驗(yàn)很好。
【優(yōu)點(diǎn)】
1、對開發(fā)人員指定的表格沒有任何影響;
2、使用簡單;
3、被定義的表格樣式可以隨意的定制你的樣式,不對你的樣式構(gòu)成影響;
4、移植性好,擴(kuò)展性好。
【缺點(diǎn)】
目前用IE7測試正常,但不支持FireFox,工作比較忙,沒時間更正,希望網(wǎng)友更正,俺在此謝過。^_^

【使用方法】
1、將AutoTableSize.js包文件[點(diǎn)擊這兒下載源代碼]導(dǎo)入到你的web應(yīng)用目錄中;
2、引入包AutoTableSize.js,頁面body底部加入:
<script type="text/Javascript" src="AutoTableSize.js"></script>
3、編寫你的腳本調(diào)用:
new AutoTableSize(); 當(dāng)DOM對象中只有一個Table的時候不用指定Table的ID屬性;
new AutoTableSize(table); table:既可以是表格的ID屬性,也可以是表格對象;
源碼AutoTableSize.js
復(fù)制代碼 代碼如下:
/**
* @ version: 1.0
* @ author:Xing,Xiudong
* @ email:    xingxiudong[at]gmail.com
* @ index:    http://blog.csdn.NET/xxd851116
* @ date:    2009.04.01 愚人節(jié)
* @ 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");
    }
}

JavaScript技術(shù)HTML 自動伸縮的表格Table js實(shí)現(xiàn),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产成人理在线观看视频 | 国产一区二区三区精品视频 | 2021国产精品一区二区在线 | 国产激情小视频 | 久久精品久久精品久久精品 | 综合国产在线 | 日韩视频一区二区 | 视频一区在线观看 | 久久亚洲精品成人 | 伊人网在线播放 | 丁香视频在线观看播放 | 久久久久777777人人人视频 | 久久综合九九亚洲一区 | 日本大片免a费观看视频+播放器 | 美女视频黄.免费网址 | 日韩欧美一中文字幕不卡 | 夜夜影院未满十八勿进 | 国产精品日韩欧美久久综合 | 国产91小视频 | 国产剧情在线视频 | 国产一区美女视频 | 久久精品综合 | 黄色网在线免费观看 | 免费播放美女一级毛片 | 国产一级特黄一级毛片 | 视色4se影院在线播放 | 加勒比色综合 | 在线观看色网 | xxx久久| 五月婷婷丁香网 | 在线国产一区二区三区 | 色综合久久六月婷婷中文字幕 | 真实国产乱子伦在线观看 | 一区亚洲| 久久香蕉精品 | 国产乱码精品一区二区 | 美女张开腿让男人桶爽免费看 | aabb片免费看| 四虎永久在线日韩精品观看 | 综合色亚洲 | 手机在线看片不卡中文字幕 |