简体   繁体   English

如何打印隐藏的文章(Css / JQuery)

[英]How to print a hidden article(Css/JQuery)

I´d like to print an article which is hidden because of Javascript/Jquery. 我想打印一篇由于Javascript / Jquery而被隐藏的文章。 This is only a short snippet of the real code. 这只是真实代码的一小段。 In the real code there are button with who you can show the "class2". 在真实代码中,有一个按钮可以显示“ class2”。 When you click, class1 is hidden and class2 is shown. 单击时,将隐藏class1,并显示class2。 When the user want to print he should be able to print all wether a class is hidden or not. 当用户想要打印时,无论是否隐藏一个类,他都应该能够打印所有内容。

<article class="x class1">
        <section>
            <p>1</p>
        </section>
        <section>
            <p>1</p>
        </section>
    </article>
    <article class="x class2">
        <section>
            <p>2</p>
        </section>
        <section>
            <p>2</p>
        </section>
    </article>
    <script type="text/javascript">

            $(document).ready(function () {

                $(".x").hide()
                $(".class1).show()

            });
    </script>

See the fiddle: http://jsfiddle.net/vfub0d50/1/ 参见小提琴: http : //jsfiddle.net/vfub0d50/1/

<article class="x class1">
        <section>
            <p>1</p>
        </section>
        <section>
            <p>1</p>
        </section>
    </article>
    <article class="x class2">
        <section>
            <p>2</p>
        </section>
        <section>
            <p>2</p>
        </section>
    </article>

CSS 的CSS

.hide{
    display: none;
}

    @media print {
        .class2 {
        display:block;    
        }
    }

jQuery jQuery的

$(document).ready(function () {
    $(".class2").addClass('hide');
});

This works because I don't use .hide() and . 之所以有效,是因为我不使用.hide()和。 show() which adds inline css and thus overriding every other possible style. show()会添加内联css,从而覆盖其他所有可能的样式。 This adds a class to hide a div . 这将添加一个类以隐藏div No inline css is added with this method. 此方法不添加任何内联CSS。

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

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