You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何removeAttribute API单独移除is属性时在outerHTML中不生效?

问题:移除Web Components的is属性后outerHTML未同步更新

复现代码

var div = document.createElement("div");
var html = "<div id='issue' is='if'> some content </div>";
div.innerHTML = html;
document.body.appendChild(div);
var newDiv = document.querySelector("#issue");
newDiv.removeAttribute("id");
console.log(newDiv.outerHTML);
newDiv.removeAttribute("is");
console.log(newDiv.getAttribute("is"));
console.log(newDiv.outerHTML);

问题现象

调用removeAttribute移除is属性后,通过getAttribute("is")可确认该属性在DOM中已被移除(返回null),但outerHTML的输出结果里仍保留着is属性。已知is是Web Components的特殊属性,但移除属性后outerHTML未同步更新的表现不符合预期。

内容的提问来源于stack exchange,提问作者MOHAMED SIKKANDAR AFZAL M

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 02:12:42