zoukankan      html  css  js  c++  java
  • JavaScript 关于动态添加表格行问题





    strHtml="<table border=1 id=McGrid1>"
    strHtml=strHtml + "<tr><td align='center' style='display:none'>编号</td><td align='center' width='60'>姓名</td</tr></table>"
    document.write(strHtml)

    tr=document.all.McGrid1.insertRow()
    td=tr.insertCell()
    //tr.insertCell(0).style.display="none"
    //tr.insertCell(0).innerText="012"
    td.style.display="none"
    td.innerText="012"
    td=tr.insertCell()
    td.innerText="张三"

    //tr.insertCell(1).innerText="张三"
    alert(tr.cells(1).innerText);

    =========================================

    rows

    Every table contains a rows collection, which consists of all the rows in a table, including the header and footer rows. You can use the insertRow method to add a row to a table and, consequently, to its rows collection. Each row is equivalent to a tr element in HTML. The following code appends an empty row to the rows collection of a table called oTable.

    var oRow
    oRow = oTable.insertRow();

    By default, the insertRow method appends a row to the end of the collection; this is faster than inserting a row somewhere in the middle of the collection. However, to insert a row into the middle of a collection, you can pass an index to insertRow, as shown in the following code.

    var oRow
    oRow = oTable.insertRow(3);

    The index on the rows collection starts at zero. Therefore, the preceding code inserts a row at the fourth position of the rows collection of oTable. Once a row is created, you can insert cells into it. This is discussed in the next section.

    Note   The innerText and innerHTML properties are read-only on the tr object. Therefore, you cannot use them to insert text or HTML into a row. You can, however, insert td objects into a row using the insertCell method. Then, you can insert text or HTML into the td objects by setting the innerText or innerHTML property of the cell.

    You can access the members of the rows collection by using an index, the same way you access an array. Consider the following code, which iterates through the rows of oTable and sets the font to bold for each row. The code uses array syntax to access the individual members of the rows collection. The length property is used to determine the number of elements in a collection.

    var curr_row;
    
    for (curr_row = 0; curr_row < oTable.rows.length; curr_row++)
    {
      oTable.rows[curr_row].style.fontWeight = "bold";
    }

    cells

    After a row is created, you can add cells to it; each row contains a cells collection. To append cells to the cells collection of a row object, call the insertCell method of the row object.

    Note   By default, the insertCell method adds cells to the end of the collection, because it is faster to add a cell at the end of a row than somewhere in the middle.

    The following example inserts a row into a table, and then it inserts a cell into the newly inserted row.

    var oRow;
    var oCell;
    
    oRow = oTable.insertRow();
    oCell = oRow.insertCell();

    Once an empty cell is added to a row, you can insert HTML into the cell by setting its innerHTML property.

    var oRow;
    var oCell;
    
    oRow = oTable.insertRow();
    oCell = oRow.insertCell();
    oCell.innerHTML = "Download the latest version of <I>Internet Explorer</I> from here."

    oRow.insertCell(3) 不是第3个位置的表格而是在第3个位置插入的表格!



  • 相关阅读:
    树莓派4B 多屏 QT程序窗口全屏 QScreen 只能获取1个屏幕
    树莓派4B 微雪7寸触摸屏 双屏 触摸屏校正
    虚拟机 ubuntu18 树莓派4 QT5.14.2 交叉编译
    Qt 指定 so库 运行时路径
    building qtqml requires python
    python django 测试报告 发送邮件
    jmeter XPath Extractor
    python+unittest+HTMLTestRunner生成测试报告
    Genymotion、 uiautomatorviewer、 appium报错
    jmeter forEach控制器
  • 原文地址:https://www.cnblogs.com/goody9807/p/115930.html
Copyright © 2011-2022 走看看