简体   繁体   English

使用可见性:隐藏和显示:CSS中没有?

[英]Using visibility: hidden and display: none together in CSS?

The reason I want to use the together is that I want to hide the content like display: none does, without leaving any whitespace as visibility: hidden does. 我想一起使用的原因是我想像display一样隐藏内容:none,而不会像可视性那样保留任何空格:hidden。

At the same time I want the hidden content not to be copied when the user copies the entire table from the webpage, not because it is sensitive information but because the user hid the field and therefore doesn't want it copied. 同时,我希望在用户从网页复制整个表时不要复制隐藏内容,这不是因为它是敏感信息,而是因为用户隐藏了该字段,因此不希望复制它。 visibility: hidden doesn't copy but display: none does, so I have quite a dilemma. 可见性:隐藏不会复制,但显示:没有,所以我很困惑。

Anyone know a solution? 有人知道解决方案吗?

Edit: 编辑:
What I ended up doing was just what was suggested, save the information as Javascript (as it is not sensitive information anyways) and create/remove dynamically with Javascript. 我最终所做的只是建议的操作,将信息另存为Javascript(因为它始终不是敏感信息),并使用Javascript动态创建/删除。

I do not think giving the element visibility: hidden prevents the user copying the information in the table, although this may be browser specific behavior. 我认为不给元素以visibility: hidden可以防止用户复制表中的信息,尽管这可能是浏览器特定的行为。 Have a look at the test I've set up: http://jsfiddle.net/a9JhV/ 看看我设置的测试: http : //jsfiddle.net/a9JhV/

The results from Firefox 3.6.8 on Windows 7 is Windows 7上的Firefox 3.6.8的结果是

Copy ME!    Don't copy me :(    Copy ME!    Copy ME!
Copy ME!    Don't copy me :(    Copy ME!    Copy ME!

Which doesn't work as expected. 这不能按预期工作。


I've cooked up some code, it took the quite a bit work of cook up... have a look here: http://jsfiddle.net/a9JhV/7/ 我已经编写了一些代码,完成了很多工作……在这里看看: http : //jsfiddle.net/a9JhV/7/

It uses jQuery to hide and show the table columns - actually removes them from the DOM, not just play around with their visibility and whatnot. 它使用jQuery来隐藏和显示表列-实际上是将它们从DOM中删除,而不仅仅是玩弄它们的可见性和其他内容。 Whee! 呜!

Why not remove the node from the page? 为什么不从页面中删除节点? You could accomplish this by using: 您可以使用以下方法完成此操作:

<script type = 'text/javascript' language = 'JavaScript'>
document.getElementById('yourDivId').innerHTML = '';
//OR
document.removeChild(getElementById('yourDivId')); //(I think this is right...document might need to be replaced by the div's parent)
</script>

You should remove the "hidden" DOM object using javascript and then recreate it again if user wants it back. 您应该使用javascript删除“隐藏的” DOM对象,然后在用户需要时重新创建它。 Data from deleted records can be stored in session storage or hidden inputs for example. 例如,已删除记录中的数据可以存储在会话存储或隐藏输入中。

If you want elements HIDDEN from the source, place them in a separate text file and load it using an ajax-like call... this will prevent the html from being in the source. 如果要从源中隐藏元素,请将其放在单独的文本文件中,然后使用类似ajax的调用加载...这将防止html出现在源文件中。

If you place a clear image OVER the content they also will not be able to highlight it easily (and by using javascript you can likely disable their ability to do a ctrl+a) 如果您在内容上放置清晰的图像,他们也将无法轻松突出显示该图像(并且通过使用JavaScript,您可能会禁用其执行ctrl + a的功能)

hope that helps! 希望有帮助!

It's a good idea to create an object to represent the table: 创建一个代表表的对象是一个好主意:

var myTable = function(tableName){
    // If you want to assign columns dynamically you could create this.addColumn();
    this.Columns = new Array(
                   new Array("row1","row2","row3","row4"),
                   new Array("row1","row2","row3","row4")
                   );

    this.reBuild = function(){
        for (col in this.Columns){
            for(row in this.Columns[col]){
                // put the cell in the table
            }
        }
    };
};

I didn't test this code, it should just illustrate the gist of storing and building a table. 我没有测试此代码,它只是说明了存储和构建表的要点。

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

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