简体   繁体   English

隐藏元素时如何从源中隐藏元素?

[英]How to hide an element from the source when it is hidden?

When using display: none you can still see the contents of the element in the source code.使用display: none时,您仍然可以在源代码中看到元素的内容。

Is there a way to prevent this using JavaScript, PHP or some other approach?有没有办法使用 JavaScript、PHP 或其他方法来防止这种情况发生?

You havent gave much infomation about if you mean view source or inspect element, what you can do is set the insides of the element to nothing, by doing this:如果您的意思是查看源或检查元素,您还没有提供太多信息,您可以做的是通过执行以下操作将元素的内部设置为空:

<script>document.getElementById('myElement').innerHTML = "";</script>

When viewing the element from inspect element, the insides of your element will simply be gone,从检查元素查看元素时,元素的内部将消失,

The downside is its still viewable on view-source, i cant think of a fix to this缺点是它仍然可以在视图源上看到,我想不出一个解决办法

i wouldn't recommend doing it this way because if your making some kind of admin dashboard the dashboard's code is publicly visible, if you want to hide it perminantly use PHP as anything in the我不建议这样做,因为如果您制作某种管理仪表板,仪表板的代码是公开可见的,如果您想永久隐藏它,请使用 PHP 作为

<?php
//Code
?>

is only viewable to the server, not the client.只对服务器可见,对客户端不可见。

If your interested in PHP i would recommend having a look at this source: https://www.w3schools.com/php/php_intro.asp如果您对 PHP 感兴趣,我建议您查看以下来源: https://www.w3schools.com/php/php_intro.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM