4

我有以下 div:

<div visible="false" 
     style="background-image:url('../Contents/Images/item-background-selected.png'); width:113px; height:58px; background-repeat: no-repeat; position: absolute;"  />
<div>

尽管visible属性设置为,它仍然可见false。但是当我background-image从样式中删除它时它被隐藏了。

如何在保持背景的情况下隐藏它?

提前致谢。

4

3 回答 3

6
 visible="false" 

是一个服务器控件属性,除非 div 有

 runat="server" 

设置,它将被忽略,因为浏览器/客户端不知道如何处理它。

尝试使用 CSS:

.myDivClass {

  display:none; /** or: visibility:hidden;  which is slightly different **/

  background-image:url('../Contents/Images/item-background-selected.png');
  width:113px; 
  height:58px; 
  background-repeat: 
  no-repeat; 
  position: absolute
}
于 2011-01-18T14:37:03.873 回答
3

试一试:

<div 
     style="background-image:url('../Contents/Images/item-background-selected.png'); width:113px; height:58px; background-repeat: no-repeat; position: absolute; display:none"  />
<div>

注意“显示:无”

要使其再次可见,您必须从 div 中删除 display:none。

于 2011-01-18T14:30:19.620 回答
1

如果你想在 jQuery 中实现这一点,请使用showand hide

https://api.jquery.com/hide/

例子:

$(document).ready(function() {
    $('report').hide(); // no milliseconds provided means it hides immediately
});

function databound(e) {
    var data = e.sender.dataSource;
    if (0 < data.total()) {
        $('report').show(2000); // 2 seconds to open fully
    }
}

边走边学,分享我的发现。

于 2021-01-20T22:08:45.127 回答