类型错误:属性 1 不可配置,无法删除

TypeError: property 1 is non-configurable and can't be deleted

本文关键字:配置 删除 错误 属性 类型      更新时间:2023-09-26

对于下面的页面,

<body>
    <form name="testForm" action="webtunings.php" method="get">
        <input type="text" name="city">
        <input type="submit">
    </form>
    <form action="test.php" method="post" id="id1">
        <input type="radio" name="isCorrect" value="yes" >
        <input type="radio" name="isCorrect" value="no">
    </form>
</body>

下面的代码,

> var obj = document.getElementsByTagName('form')
    undefined
> obj
    HTMLCollection [ <form>, <form#id1> ]
> Array.prototype.pop.call(obj);

给出错误:TypeError: property 1 is non-configurable and can't be deleted

下面的代码成功删除form元素,

> var obj = document.getElementById("id1")
    undefined
> obj.parentNode.removeChild(obj)

使用Array.prototype.pop,为什么浏览器说obj的不可配置属性不像第二种方法?

HTML 集合包含 DOM 中表单元素的实时列表。

如果从 DOM 中删除表单,则列表将自动更新。

不能直接从列表中删除该元素。它旨在禁止这种情况。