js添加行删除行

 function AddRow(tableID) {
            var tab = document.getElementById(tableID);
            tab.border = "1px";
            var newRow = tab.insertRow(tab.rows.length);
            var colsCount = document.getElementById(tableID).rows.item(0).cells.length;
            for (var i = 0; i < colsCount; i++) {
                var cell = newRow.insertCell(i);
                var id = "txt";
                if (i == 0) {
                 
                    id += "Cw";
                }
                if (i == 1) {
                    id += "mdcSy";
                }
                if (i == 2) {

                    id += "mdcYx";
                }
                var mess = "<input type='input' id='" + id + "'/>";
                cell.innerHTML = mess;
              
            }
        }
        function DelRow(tableID) {
            var tab = document.getElementById(tableID);
            var rowIndex = tab.rows.length - 1;
            if (rowIndex < 1) {
            alert("表头无法删除!")
            }
            else {
                tab.deleteRow(rowIndex);
            }
        }
        function DelRow(tableID) {
            var tab = document.getElementById(tableID);
            var rowIndex = tab.rows.length - 1;
            if (rowIndex < 1) {
                alert("表头无法删除!")
                return false;
            }
            else {
                return true;
            }
        }

posted @ 2011-01-04 14:58  居后不争  阅读(864)  评论(0编辑  收藏  举报