使用JavaScript清除HTML页面 [英] Clear HTML page using JavaScript

查看:73
本文介绍了使用JavaScript清除HTML页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法删除带有JavaScript功能的页面上现有内容的部分内容?

喜欢这样:

Is there any way to delete portions of existing content on a page with a JavaScript function?
Like this:

<I WANT THIS CLEARED>
<IS THERE ANY JAVASCRIPT OR HTML STATEMENT I CAN PUT HERE?>
<I WANT THIS DISPLAYED>

我应该把什么放在<是否有任何JAVASCRIPT或HTML声明我可以放在这里吗?>

我知道在零件之后加上< div style =display:none>< plaintext> 我想显示将隐藏页面的结尾,但如何清除开头?

I know putting <div style="display:none"><plaintext> after the part I want displayed will hide the end of a page, but how do I clear the beginning?

推荐答案

您可以使用 document.body.innerHTML =。只要浏览器处理页面,它就会取出正文中的所有内容。请参阅以下示例:

You can use document.body.innerHTML = "". It will take out everything in the body so far as the browser processes the page. See the following example:

<html>
    <head></head>
    <body>
        <p>This should not appear</p>

        <script type="text/javascript">
            document.body.innerHTML = '';
        </script>

        <p>This should appear.</p>
    </body>
</html>

然而,这并不是实现这一目标的好方法。如果你想隐藏一些文本,可以考虑其他人提到的jQuery。

This is, however, not a great way to accomplish this. If you want some text hidden, consider jQuery as others have mentioned.

这篇关于使用JavaScript清除HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆