2

我在 Chrome 上遇到 JavaScript 错误

Uncaught TypeError: Object #<HTMLInputElement> has no method 'removeNode'

我的代码是

if (document.form["act[" + actArry["'" + i + "'"][i] + "]"] != undefined)
    document.form["act[" + actArry["'" + i + "'"][i] + "]"].removeNode(true);

并且存储在该input元素中的值是

<input type="hidden" name="act[1]" value="7813e7-true">

其实我想删除-truewhen checkboxis unchecked

这在 IE 中可以正常工作,但在 Google Chrome 中不能正常工作。

谁能告诉我这是什么问题,哪个应该是 IE 和 Chrome 中的常用方法?jQuery中有替代方案吗?

4

2 回答 2

7

removeNode()是一种仅限 IE 的方法。它不适用于其他浏览器。

您可以在父节点上执行相同的操作以及跨浏览器。removeChild()

IE:

if (node.parentNode)
   node.parentNode.removeChild(node);

参考:http://www.sitepoint.com/forums/showthread.php?126312-Mozilla-equivalent-for-IE-s-removeNode()

于 2013-05-23T06:04:12.110 回答
1

您可以使用 removeChild,它适用于大多数浏览器。

于 2013-05-23T06:06:05.340 回答