HTML Table 的 insertBefore 方法中的 InvalidArgument

发布于 2024-09-15 18:43:40 字数 999 浏览 1 评论 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;
}

I think I know this is an IE bug ...
I need to add new row to an HTML table at the exact position.
(don't want insertRow(index) cuz this looks like gonna be better for some other reasons)

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

dawn曙光 2024-09-22 18:43:40

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

My guess is that td.parentNode is not a child element of grid. Take a look at the W3C specification for insertBefore to make sure that you are calling the method with valid parameters.

清眉祭 2024-09-22 18:43:40

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

I would guess that you're passing in an invalid argument to AddNewItem, that (in IE, at least) it's not a td element like you think.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文