javascript 如何使用javascript清除屏幕?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9967496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 08:22:43  来源:igfitidea点击:

How can I clear the screen with javascript?

javascript

提问by iKlsR

How can I clear or refresh the page in the browser using javascript? I have a loop that prints a string to the page each second and I want to clear the screen each time it updates.

如何使用javascript清除或刷新浏览器中的页面?我有一个循环,每秒向页面打印一个字符串,每次更新时我都想清除屏幕。

回答by

If you append your string to the document body, you can just use

如果将字符串附加到文档正文,则可以使用

document.body.innerHTML = "";