js添加删除行

来源:互联网 发布:高级软件测试技术 编辑:程序博客网 时间:2024/05/21 07:06
 <html xmlns="http://www.w3.org/1999/xhtml"><head>    <title></title>    <script type="text/javascript">        function insertRow(tbIndex) {            var objRow = Binddata.insertRow(tbIndex);            var objCel = objRow.insertCell(0);            objCel.style.display = "none";            objCel.innerText = tbIndex;            var objCel = objRow.insertCell(1);            objCel.innerText = document.getElementById("myCell1").value;            var objCel = objRow.insertCell(2);            objCel.innerText = document.getElementById("myCell2").value;            var objCel = objRow.insertCell(3);            objCel.innerText = document.getElementById("myCell3").value;            var objCel = objRow.insertCell(4);            objCel.innerText = document.getElementById("myCell4").value;            var objCel = objRow.insertCell(5);            objCel.innerHTML = "<a href='javascript:void(0)' onclick='javascript:del();'>删除</a>";            //            objRow.attachEvent("onclick", getIndex);            objRow.style.background = "pink";        }        function del() {            inRowIndex = event.srcElement.parentNode.parentNode.rowIndex;            Binddata.deleteRow(inRowIndex);        }        //        function getIndex() {        //            intRowIndex = event.srcElement.parentNode.parentNode.rowIndex;        //            alert("getIndex:" + intRowIndex);        //            pos.innerText = intRowIndex;        //            return intRowIndex;        //        }    </script></head><body>    <div id="getTable" onload="pos.innerText=intRowIndex;">        <table>            <!--<tr>                <td colspan="6">                    当前位置:<span id="pos"></span>                </td>            </tr>-->            <tr>                <td colspan="6">                    <table width="100%" id="Binddata">                        <thead id="thead">                            <tr>                                <th>                                    ID                                </th>                                <th>                                    配件名称                                </th>                                <th>                                    使用数量                                </th>                                <th>                                    价格                                </th>                                <th>                                    单位                                </th>                                <th>                                    操作                                </th>                            </tr>                        </thead>                        <tbody id="tbody">                            <%=BindTable()%>                        </tbody>                    </table>                </td>            </tr>            <tr>                <td align="center">                    配件名称:<input type="text" id="myCell1" name="myCell1" value="CGI" />                </td>                <td align="center">                    使用数量:<input type="text" id="myCell2" name="myCell2" value="CGI" />                </td>                <td align="center">                    价格:<input type="text" id="myCell3" name="myCell3" value="CGI" />                </td>                <td align="center">                    单位:<input type="text" id="myCell4" name="myCell4" value="CGI" />                </td>                <td colspan="2" align="center">                    <input type="button" name="Submit" value="添加" onclick="insertRow(Binddata.rows.length)" />                </td>            </tr>        </table>    </div></body></html>

 
原创粉丝点击