Javascript错误“Uncaught TypeError:Object#<htmlinputelement>没有方法'removeNode'”</htmlinputelement>

时间:2013-05-23 06:02:11

标签: javascript jquery

我在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">

实际上我想在-truecheckbox时删除unchecked

这在IE中正常运行,但在谷歌浏览器中无效。

有人可以告诉我这是什么问题,哪些应该是IE和Chrome中的常用方法? jQuery中有替代品吗?

2 个答案:

答案 0 :(得分:7)

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

您可以在父节点上执行removeChild() ,以实现相同的跨浏览器。

即:

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

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

答案 1 :(得分:1)

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