【问题标题】:How do I add styling to a javascript? [closed]如何为 javascript 添加样式? [关闭]
【发布时间】:2012-03-19 22:14:49
【问题描述】:

我有一个带有数据网格的页面,当我打印它时,我只想打印数据网格。单击打印时,页面中的所有其他元素(左侧导航、页眉、页脚等)都将被删除,并且仅显示必要的部分(位于名为 printdiv 的 div 中)。但不幸的是,我无法让它显示我想要的背景。请帮忙!!! 我需要背景为白色,但它是灰色的,这是网站其余部分的背景,有没有办法单独更改表单的背景?

这是我正在使用的 javascript

            <div id="printDiv" >

                <div id="maincontent-right-wrapper">
                    <div class="page-heading">
                        <spring:message
                            code="rmp.store_performance_yearly.page_header.store_performance_yearly" />
                    </div>

                    <!--shop starts-->
                    <div class="shop-promoter-wrapper">
                        <div class="shop-promoter-inner">

                            <ul>
                                <li><spring:message
                                        code="rmp.store_performance_yearly.label.store" /></li>
                                <li>&nbsp;</li>
                                <li><form:select path="storeid">
                                        <form:options items="${StoreList}" itemValue="storeId"
                                            itemLabel="storeName" />
                                    </form:select></li>
                                <li><img src="../static/images/spacer.gif" width="26"
                                    height="1" /></li>

                                <li><spring:message
                                        code="rmp.store_performance_yearly.label.year" /></li>
                                <li>&nbsp;</li>
                                <li><form:select path="year">
                                        <form:options items="${YearList}" />
                                    </form:select></li>

                                <li>&nbsp;</li>
                                <li><a href="#" onclick="callGo(1)">
                                        <div class="button-wrapper">
                                            <div class="button-left">&nbsp;</div>
                                            <div class="button-middle">
                                                <spring:message
                                                    code="rmp.store_performance_yearly.button.go" />
                                            </div>
                                            <div class="button-right">&nbsp;</div>
                                        </div>
                                </a></li>

                            </ul>

                        </div>
                    </div>

【问题讨论】:

  • 请提供更多信息。你试过什么?您当前的代码是什么样的?等
  • 代码值一千字...
  • 这就是我的称呼:
     
     

标签: javascript html css background-color


【解决方案1】:

代码值一千字,但仅供参考的浏览器通常不打印背景,是否打印是用户控制的设置。所以你最好的选择是不使用背景(浏览器不打印它们是有原因的,结果往往不是很好)或制作任何你想在页面上拥有实际元素的背景,在 div 后面( Z 顺序较低)。

【讨论】:

    【解决方案2】:

    你可以用 css 做到这一点。您所要做的就是添加另一个用于打印的 css 声明,如下所示:

    <LINK rel="stylesheet" type"text/css" href="print.css" media="print">
    

    因此您可以使用以下类:

    .style1 {display: none;}
    

    在您不想打印的每个元素的 print.css 文件中

    【讨论】:

    • 你的意思是.noPrint { display:none} 并把class="noPrint" 给你不想打印的对象
    • 不,我不是那个意思。我的意思是在print.css 文件中使用display: none,这样打印时就不会显示它们。无论如何,我已经编辑了我的答案,以便style 关键字不会混淆
    • 是的,你确实是这个意思。你把你的答案改成了我所说的那样。 print.css 中的 .noPrint 和对象上的 noPrint 类
    猜你喜欢
    • 2011-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-23
    相关资源
    最近更新 更多