简体   繁体   English

我应该使用Javascript,CSS或隐藏控件呈现的图像的内容吗?

[英]Should i use Javascript, CSS or what to hide an image rendered by a control?

I would like to hide the background image of the ReportView control which is toolbar_bk.png By saying hide actually i would like to set it to none. 我想隐藏ReportView控件的背景图像,这是toolbar_bk.png通过说hide实际上我想将它设置为none。

So how could i easily do it? 那我怎么能轻松做到呢? Server side, CSS, Javascript or even better JQUERY? 服务器端,CSS,Javascript甚至更好的JQUERY? I am totally lost with this one. 我完全迷失了这个。

Here is the rendered part 这是渲染的部分

<div id="ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_ReportViewer1_ctl05" 
  style="font-family:Verdana;font-size:8pt;border-bottom:1px #CCCCCC Solid;
  background-color:#F7F7F7;
  background-image:url(/domain-name.com/Reserved.ReportViewerWebControl.axd?
  OpType=BackImage&Version=10.0.40219.329&
  Color=%23F7F7F7&Name=Microsoft.Reporting.WebForms.Icons.toolbar_bk.png);">

Please note that it's always CSS what hides your element or shows your background etc. You just can put it inline, into an external file or create it dynamically via a script language (ie JavaScript), eventually by use of a JavaScript library as jQuery. 请注意,它总是CSS隐藏您的元素或显示您的背景等。您可以将其内联,放入外部文件或通过脚本语言(即JavaScript)动态创建,最终使用JavaScript库作为jQuery。

To your question: Just don't create the inline style serverside, and everything is well. 对于你的问题:只是不要创建内联样式服务器端,一切都很好。

I'm not sure this is what you want. 我不确定这是你想要的。 Here's an answer nevertheless.. 不过这是一个答案..

Wrap them with their own div. 用他们自己的div包裹他们。 Let's give that div a class of "wrapper". 让我们给这个div一类“包装”。 on the css side paste this: 在CSS端粘贴这个:

.wrapper * { background-image: none; .wrapper * {background-image:none; } }

With jQuery, you would simply do this: 使用jQuery,您只需执行此操作:

$('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_ReportViewer1_ctl05').css('background-image', 'none');

With just plain javascript: 只需简单的javascript:

document.getElementById('ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_ReportViewer1_ctl05').style.backgroundImage = 'none';

With css in the page or in external style sheet: 使用页面中的css或外部样式表:

#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_ReportViewer1_ctl05 { background-image:none !important}
  1. Best option -- Configure the server control to not set a background image. 最佳选项 - 将服务器控件配置为不设置背景图像。
  2. If #1 is not possible, you could write JavaScript to manipulate the HTML after it loads. 如果#1不可能,您可以编写JavaScript以在加载后操纵HTML。

Here's a jQuery example if you need to use option 2: 如果你需要使用选项2,这是一个jQuery示例:

$('[id~="ReportViewer1"]').css('background-image', 'none');

Use jquery addClass() function as follows 使用jquery addClass()函数如下

<style>
            .report
            {
                background-color: #D6E3F3;
                /* background-image: url("/Reserved.ReportViewerWebControl.axd?OpType=BackImage&Version=10.0.30319.1&Color=%23ECE9D8&Name=Microsoft.Reporting.WebForms.Icons.toolbar_bk.png");*/
                border-bottom: 1px solid #CCCCCC;
                font-family: Verdana;
                font-size: 8pt;
            }
            </style>


<script>
    $(document).ready(function () {
        $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_ReportViewer1_ctl05').removeAttr('style');
        $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_ReportViewer1_ctl05').addClass('report');
    });
</script>

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

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