AI摘要
在JavaScript中执行`document.write()`方法时,会重写整个当前页面。这意味着页面原有的所有HTML元素和控件都将被清除,仅保留`document.write()`输出的新内容。因此,在页面加载完成后调用该方法会导致原有控件消失。
JavaScript执行document.write()原有控件消失
<!DOCTYPE html>
<html>
<meta charset="utf8">
<body>
<input type="button" value="点我" onclick="document.write('按钮消失')" style="position: absolute;width: 200px;height: 100px;left: 0;right: 0;top: 0;bottom: 0;;margin: auto;">
</body>
</html>
评论 (0)