当前位置:学会吧培训频道电脑知识学习网页制作Javascript教程javascript代码创建表格类» 正文

javascript代码创建表格类

[08-08 00:41:13]   来源:http://www.xuehuiba.com  Javascript教程   阅读:8638
概要:表格类的原型函数:用于以表格方式表现从xml中读取的数据//---// Yang Xiaodong// IRSA, CAS//---//Class :DataTable//Purpose :provides a table class//---//Calls :None//Called by :None//---//Arguments :tableTitles the Column or Row titles of table// tableValues A 2 dimension Array to represent values in table// alignDirect the title align direct of table, 0 is horizontal or titles in coloumns, 1 is vertical or titles in rows//Globals :None//Re
javascript代码创建表格类,标签:javascript视频教程,javascript教程下载,http://www.xuehuiba.com

表格类的原型函数:用于以表格方式表现从xml中读取的数据
//-------------------------------------------------------
//   Yang Xiaodong
//   IRSA, CAS
//-------------------------------------------------------
//Class     :DataTable
//Purpose   :provides a table class
//-------------------------------------------------------
//Calls     :None
//Called by :None
//-------------------------------------------------------
//Arguments :tableTitles    the Column or Row titles of table
//           tableValues    A 2 dimension Array to represent values in table
//           alignDirect    the title align direct of table, 0 is horizontal or titles in coloumns, 1 is vertical or titles in rows
//Globals   :None
//Returns   :table element
//-------------------------------------------------------
//Notes     :None
//-------------------------------------------------------
//History   :2007/10/27  1.0
//=======================================================

http://bizhi.knowsky.com/
var DataTable = function(tableTitles, tableValues,alignDirect)
{
    var table = document.createElement("table");
    var tbody = document.createElement("tbody");
    table.appendChild(tbody);
   
    if (alignDirect == 0)         //Columns Mode
    {
        var nColumns = tableTitles.length;
        var nRows = tableValues.length + 1;
        for (var i = 0; i < nRows; i++)
        {
            tbody.insertRow(i);
            for (var j = 0; j < nColumns; j++)
            {
                tbody.rows[i].insertCell(j);
                if (i == 0)
                {
                    tbody.rows[i].cells[j].appendChild(tableTitles[j]);
                }
                else
                {
                    tbody.rows[i].cells[j].appendChild(tableValues[i-1][j]);
                }
            }
        }
    }
    else                        //Rows Mode
    {
        var nRows = tableTitles.length;
        var nColumns = tableValues.length + 1;
        for(var i = 0; i < nRows; i++)
        {
            tbody.insertRow(i);
            for (var j = 0; j < nColumns; j++)
            {
                tbody.rows[i].insertCell(j);
                //tbody.rows[i].cells[j].setAttribute("align", "left");
                if (j == 0)

[1] [2]  下一页


Tag:Javascript教程javascript视频教程,javascript教程下载电脑知识学习 - 网页制作 - Javascript教程
Copyright 学会吧 All Right Reserved.
在线学习社区!--学会吧
1 2 3 4 5 6 7 7 8 9 10 11 12 13