javascript - 如何打印与显示完全相同的 Bootstrap 模态?

标签 javascript jquery html css twitter-bootstrap

所以我很难用它的CSS打印模态。我想打印出一个与屏幕上显示的完全一样的模式窗口。我使用过 window.print() 命令,甚至使用了 javasript/jquery 命令。但没有附加CSS。相反,它只打印一半的模态。

所以,我想要的是这个模态图像: Modal Example Image

将按照屏幕上显示的内容打印到window.print()。整个模态 block 带有边框等,但后面没有页面。

我尝试过的代码:

function printElement(elem) {
        var domClone = elem.cloneNode(true);

        var $printSection = document.getElementById("printSection");

        if (!$printSection) {
            var $printSection = document.createElement("div");
            $printSection.id = "printSection";
            document.body.appendChild($printSection);
        }

        $printSection.innerHTML = "";
        $printSection.appendChild(domClone);
        window.print();
    }

如果有人能回答这个问题,谢谢!

最佳答案

您可以使用@media print标签

@media print {
  model.class {
     display: none; /* Hidden by default */
     position: fixed; /* Stay in place */
     z-index: 1; /* Sit on top */
     left: 0;
     top: 0;
     width: 100%; /* Full width */
     height: 100%; /* Full height */
     overflow: auto; /* Enable scroll if needed */
     background-color: rgb(0,0,0); /* Fallback color */
     background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
  } // or you can add what ever you want css in print mood 

@media print 标记中的所有 CSS 都将仅在打印模式下应用,因此要测试样式并确保设计满足需求,您可以在 Chrome 浏览器中使用打印模式。

有关更多信息,请查看此 answer .

关于javascript - 如何打印与显示完全相同的 Bootstrap 模态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47257777/

相关文章:

javascript - 以固定尺寸 60x60 显示部分图像(未知宽度和高度)

javascript - jQuery 显示 div 为空输入字段(验证)

javascript - 使用 Node.js 创建网站

javascript - 如何在某些特定条件下在父元素列表之间附加 <ul><li> 元素

javascript - 当输入错误时,jQuery自动完成ajax无法自动更正

javascript - 如何在 2 个单独的 Div 中自动调整文本大小

html - 覆盖父溢出 - 选择

javascript - 使用 HTML LightSwitch 计算属性

javascript - 无法在页面加载时触发按钮或 anchor 元素的单击事件

javascript - 扩展帮助(后台运行时按键)