简体   繁体   English

隐藏DIV的内容

[英]Hiding the contents of DIV

I have a DIV with a script as shown below 我有一个带脚本的DIV,如下所示

<div style="text-align:center">
                <script type='text/javascript' language='JavaScript' src='http://xslt.alexa.com/site_stats/js/t/a?url=www.mysite.com'></script>
</div>

What I want is that the users should not be able to see this div on the site, but the script should be executed as in the normal way. 我想要的是用户不应在网站上看到此div,但应按常规方式执行脚本。 Please suggest! 请提出建议!

I am not sure what it is you are including with that Javascript call, but if you want to hide the contents of this DIV just add this to the style declaration: display: none; 我不确定该Javascript调用包含什么内容,但是如果您想隐藏此DIV的内容,只需将其添加到样式声明中即可: display: none;

Check out the CSS display documentation. 查看CSS 显示文档。

EDIT : The SCRIPT inside the DIV tag will still get loaded, which I believe is the desired effect. 编辑 :DIV标签内的SCRIPT仍将加载,我相信这是理想的效果。

Just change your style to 只需将您的样式更改为

<div style="text-align:center; display: none;">
                <script type='text/javascript' language='JavaScript' src='http://xslt.alexa.com/site_stats/js/t/a?url=www.mysite.com'></script>
</div>

Give your div a meaningful name. 给您的div取一个有意义的名称。

<div class="hidden">
</div>

The in the CSS add the 在CSS中添加

.hidden {
    display: none;
}

当您想使元素对用户隐藏时,将css设置为“ display:none;”。

You have to style your div with this code: 您必须使用以下代码来设置div的样式:

<div style="text-align:center; display: none; visibility: hidden;">
  <!-- other code -->
</div>

This is the way the mozilla team works, if I remember well. 如果我没有记错的话,这就是mozilla团队的工作方式。

If the JavaScript generates html code that you don't want to be visible you can write some specific styles to make these auto generated elements hidden without making your outer div hidden. 如果JavaScript生成了您不希望看到的html代码,则可以编写一些特定的样式来隐藏这些自动生成的元素,而无需隐藏外部div。 Eg if the JavaScript generates a div and fills it with content then you could do something like this: 例如,如果JavaScript生成div并用内容填充它,则可以执行以下操作:

The HTML: HTML:

div id="hideinside">
                <script type='text/javascript' language='JavaScript' src='http://xslt.alexa.com/site_stats/js/t/a?url=www.mysite.com'></script>
</div>

The CSS: CSS:

#hideinside div {
    display:none; /* hides all divs inside your outer div */
}
div.hidden {
   position: absolute;
   left: 10000px;
}

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

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