zoukankan      html  css  js  c++  java
  • JavaScript后台代码操作HTML TABLE的方法

    var rowNum = 0,fileNum = 0; //行号与列号 
    var oNewRow; //定义插入行对象 
    var oNewCell1,oNewCell2; //定义插入列对象 
    var fileNum = 1; 

    function addFileToTable(strFile) 

    fileNum +=1; 
    rowNum = document.getElementById("NewFileList").rows.length; 
    oNewRow = document.getElementById("NewFileList").insertRow(rowNum); 
    oNewRow.id = "clientRow_" + fileNum; 

    //添加第一列 
    oNewCell1 = document.getElementById("NewFileList").rows[rowNum].insertCell(0); 
    oNewCell1.innerHTML = "<input type='Text' readonly='readonly' style='border:0px;100px;' value='" + getFileName(strFile) + "' />"; 

    //添加第二列 
    oNewCell2 = document.getElementById("NewFileList").rows[rowNum].insertCell(1); 
    oNewCell2.innerHTML ="  <span name=" + fileNum + " style='cursor:hand;color:Red; text-decoration:none; font-family:@HGP?????E;' onClick='DelClientRow(this);' >X</span>"; 
    }

    ASP.NET后台代码操作HTML TABLE的方法  

    例1:该方法是读取服务器上路经为"strFilePath"的文件夹中的所有文件,并显示在页面上ID为"OldFileList"的TABLE中,注意,这个TABLE的"runat=server"。 
    public void ShowFilesIn(string strFilePath) 

    OldFileList.Rows.Clear(); 
    string[] strFileNames = GetFilesInServer(strFilePath); 
    for (int i = 0; i < strFileNames.Length; i++) 

    HtmlTableRow newRow = new HtmlTableRow(); 
    newRow.ID = "serverRow_" + i; 
    HtmlTableCell cell1 = new HtmlTableCell(); 
    HtmlTableCell cell2 = new HtmlTableCell(); 

    cell1.InnerHtml = "<input type='Text' readonly='readonly' style='border:0px;90px;' value='" + strFileNames[i] + "' />"; 
    cell2.InnerHtml = " <span name=" + strFileNames[i] + " style='cursor:hand;color:Red; text-decoration:none; font-family:@HGP?????E;' onClick='DelServerRow(this);' >X</span>"; 
    newRow.Cells.Add(cell1); 
    newRow.Cells.Add(cell2); 
    OldFileList.Rows.Add(newRow); 

    }

  • 相关阅读:
    POJ 1320 Street Numbers 解佩尔方程
    数学分支(转)
    深入理解Java类加载器(1):Java类加载原理解析
    Java类加载器的工作原理
    深入理解Java:类加载机制及反射
    类加载机制:全盘负责和双亲委托
    java底层学习
    代码面试最常用的10大算法
    程序员面试金典算法题
    了解ASCII、gb系列、Unicode、UTF-8的区别
  • 原文地址:https://www.cnblogs.com/ranran/p/4081770.html
Copyright © 2011-2022 走看看