js添加删除行

 
<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)' οnclick='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" οnlοad="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="添加" οnclick="insertRow(Binddata.rows.length)" />
                </td>
            </tr>
        </table>
    </div>
</body>
</html>


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值