JavaScript执行document.write()原有控件消失

1585364631
2022-03-03 / 0 评论 / 428 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年03月05日,已超过1477天没有更新,若内容或图片失效,请留言反馈。

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>

document.write()执行时,将重写当前页面,原有内容全部消失,只会留下document.write()所写内容

0

评论 (0)

取消