0

我想我知道这是一个 IE 错误……我需要在 HTML 表格的确切位置添加新行。(不想要 insertRow(index) 因为这看起来会更好一些其他原因)

function AddNewItem(td) {   ///td comes from button at the HTML code, <input ... onclick="AddNewItem(this.parentNode)"
  var grid = GetGrid();
  var itemIndex = $(td.parentNode).attr('index');
  ///alert(itemIndex + "'e eklenecek");
  var newRow = document.createElement('tr');
      var td1 = document.createElement('td');$(td1).addClass('td');
      var td2 = document.createElement('td');$(td2).addClass('td text r');
      var td3 = document.createElement('td');$(td3).addClass('td text r');
      var td4 = document.createElement('td');$(td4).addClass('td text r');
  $(newRow).append(td1);$(newRow).append(td2);$(newRow).append(td3);$(newRow).append(td4);

  grid.insertBefore(newRow, td.parentNode); ///THIS GIVES AN INVALIDARGUMENT error .. Any solutions will be appreciated :)
}


function GetGrid() {
 var grid = document.getElementById("MasterTableView");
 return grid;
}
4

2 回答 2

0

我的猜测是这td.parentNode不是grid. 查看 insertBefore 的W3C 规范,以确保您使用有效参数调用该方法。

于 2010-08-26T14:31:53.840 回答
0

我猜你正在向 传递一个无效的参数AddNewItem,那(至少在 IE 中)它不是td你想的那样的元素。

于 2010-08-26T16:57:20.043 回答