• table 表格操作


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title></title>
       
        <script language="javascript" type="text/javascript">
            var intRowIndex = 0;
            function insertRow(tbIndex) {
                tbIndex = GetRowsCount();
                var objRow = myTable.insertRow(tbIndex);
                var objCel = objRow.insertCell(0);
                objCel.innerText = tbIndex;
                var objCel = objRow.insertCell(1);
                objCel.innerText = document.myForm.myCell1.value;
                var objCel = objRow.insertCell(2);
                objCel.innerText = document.myForm.myCell2.value;
                objRow.attachEvent("onclick",getIndex);
                objRow.style.background = "pink";

                CalHours();
            }

            function deleteRow(tbIndex) {
                if (tbIndex != 0) {
                    myTable.deleteRow(tbIndex);
                    intRowIndex = 0;

                    for (var i = 1; i < myTable.rows.length; i++) {
                        myTable.rows[i].cells[0].innerText = i;
                    }

                    CalHours();
                }
                else {
                    alert("请选择要删除的信息!");
                }
                   
            }
            function getIndex()
            {
                intRowIndex = event.srcElement.parentElement.rowIndex;
                pos.innerText = intRowIndex;
            }

            function GetRowsCount() {
                var rows = myTable.rows.length;
                return rows;
            }

            function CalHours() {
                var hours = 0;
                for (var i = 1; i < myTable.rows.length; i++) {
                    hours += parseInt(myTable.rows[i].cells[0].innerText);
                }

                var txtHours = document.getElementById("txtHours");
                txtHours.innerHTML = hours;
            }

            function searchList() {
                var text;
                var date = document.all.txtDate.value;

                for (i = 1; i < myTable.rows.length; i++) {
                    text = myTable.rows(i).cells(0).innerText;

                    if (date == "" || date == text) {
                        myTable.rows(i).style.display = "";
                    }
                    else {
                        myTable.rows(i).style.display = "none";
                    }
                }
            }

        </script>
    </head>
    <body>
        <form name="myForm">
            <div style="margin:5px 0px 5px 30px;">
                <span style="padding-right:10px;">日期:</span>
                <input id="txtDate" type="text" style="80px;" />
                <input id="btnRefresh" type="button" value="刷新" onclick="searchList()" style="60px;" />
            </div>
           
            <div id="divList">
                <span id="pos" style="display:none;"></span>
                <table>
                    <tr>
                        <td style="text-align:right; padding-right:5px;"><span>投入工时:<span id="txtHours" style="color:Red;">0</span> H</span></td>
                    </tr>
                    <tr>
                        <td>
                            <table id="myTable" border="1">
                                <tr>
                                    <th>Num</th>
                                    <th>Text</th>
                                    <th>Value</th>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </div>
            第一栏:<input type="text" name="myCell1" value="CGI"><br>
            第二栏:<input type="text" name="myCell2" value="ASP"><br>
            <input type="button" onclick="insertRow(intRowIndex)" value="插入行">
            <input type="button" onclick="deleteRow(intRowIndex)" value="删除行">
        </form>
    </body>
    </html>

  • 相关阅读:
    NET 4.+ & .NET CORE 高性能 轻量级 ORM框架,众多.NET框架中最容易使用的数据库访问技术
    mvc cookie
    正则表达式捕获带有属性的标签
    IT第十天
    代码段
    关于java.lang中String类的学习:最特殊的数据类型(持续整理中......)
    关于String.concat()方法和StringBuffer.append()方法的学习:方法是如何追加字符到源字符串的
    关于String和StringBuffer的理解问题:指针、变量的声明、变量的值的变化
    关于字符串检索、关键词的搜索问题:已搜索过的部分不会再被纳入下次搜索的范围内
    IT第九天
  • 原文地址:https://www.cnblogs.com/OSoft/p/2083447.html
Copyright © 2020-2023  润新知