首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自modal的javascript - windows.print()在内容后显示空白

来自modal的javascript - windows.print()在内容后显示空白
EN

Stack Overflow用户
提问于 2020-06-17 16:12:13
回答 1查看 104关注 0票数 0

这个问题我已经有很长一段时间了。我正在打印一个在模式中的表格,打印预览中显示的内容是可以的,但在表格之后是一大块空白。And look like this.它在一个页面中显示了两个页面,只是为了解释我的问题,灰色背景可以通过取消选中背景图形来禁用。

这是我用来打印的代码,它在我的索引中,"_fields“是我想要打印的div的Id。

代码语言:javascript
复制
@section Scripts {
<script src="~/js/areas/human-resources/payrollmovement/index.js"></script>
<script>
    $(document).ready(function () {
        document.getElementById("btn-print").onclick = function () {
            printElement("_fields");
        }

        function printElement(div) {
            // Create and insert new print section
            var elem = document.getElementById(div);
            var domClone = elem.cloneNode(true);
            var $printSection = document.createElement("div");
            $printSection.id = "printSection";
            $printSection.appendChild(domClone);
            document.body.insertBefore($printSection, document.body.firstChild);
            window.print();

            // Clean up print section for future use
            var oldElem = document.getElementById("printSection");
            if (oldElem != null) { oldElem.parentNode.removeChild(oldElem); }


            return true;
        }
    });
</script>}

这是我的css

代码语言:javascript
复制
@media screen {
    #printSection {
    display: none;
    }
}

@media print {
body * {
    visibility: hidden;
}

#printSection, #printSection * {
    visibility: visible !important;
}

#printSection {
    position: absolute;
    left: 0;
    top: 0;
}

.modal-open .wrapper {
    display: none !important;
    visibility: hidden !important;
}
}

我想去掉表格后面的空格,以及一种复制表格的方法。

EN

回答 1

Stack Overflow用户

发布于 2020-06-19 22:34:38

我用过两个插件来打印页面的一部分,所以你应该试试。不能保证他们会解决你的问题,但他们值得一试。

https://jasonday.github.io/printThis/

https://printjs.crabbly.com/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62424392

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档