如何在打印模式下将某些html字段的值显示到表中

史蒂夫·沙巴齐(Steve Shahbazi)

我有一个带有一些图表,标签,文本框等的html页面,并希望在打印模式下以表格格式显示一些标签和文本框值。

我正在以CSS样式使用@media print,当用户按ctrl + p打印页面时,可以在其中重新定位/调整大小。

@media print {
    button, .no-print {
        display: none !important;
    }

    .myclass-print {
        border: none !important;
        position: absolute;
        top: 670px;
        left: 420px;
    }

    .comment-print {
        position: absolute;
        top: 1010px;
        left: 40px;
        width: 360px;
        word-break: break-all;
    }

    .no-border-print {
        border: none;
    }

    aside#sidebar, header[role="banner"], footer, #comments, #respond {
        display: none;
    }

    .page-header {
        vertical-align: middle;
        text-align: center;
        border-bottom: none;
    }
}
<div class="myclass-print">
     @Html.Partial("~/_MyPartial.cshtml")
</div>

在_MyPartial.cshtml中,html表中有一些文本框组件。我只想在打印模式下打印它们的值,即打印中没有下拉框或文本框,而只是它们的内容(文本)。如果有人可以与我分享解决方案,我将非常高兴。

卡莫拉

一种解决方案是使用JavaScript将文本框的值分配给页面上其他位置的其他元素。

仅在打印时显示这些元素。隐藏打印中的输入文本框。

工作示例:

// When the user prints
window.addEventListener("beforeprint", function(event) {

  // Assign the value from the input to the print only span innerText
  document.getElementById('sample-input-text').innerText = document.getElementById('sample-input').value;
});
.print-only {
  display: none;
}

.no-print {
  display: block;
}

@media print {
  .print-only {
    display: block;
  }
  
  .no-print {
    display: none;
  }
}
<input class="no-print" type="text" value="Sample Text" name="sample-input" id="sample-input">
<span class="print-only" id="sample-input-text"></span>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用HTML和CSS引导程序在打印模式下将DIV放置在首页的底部

jQuery / Javascript数据表:如何在行选择时将行数据显示到html文本字段中

如何在打印中打印包括表格边框显示?

如何将范围滑块输入字段值绑定到 html 表中的正确输入字段?

如何在php中以10的倍数增加打印模式?

如何在python 2的ascii文件中识别和打印模式?

如何在打印预览中获取输入文本字段值?

如何在pSQL会话中的特定模式下显示表?

如何在gdb / lldb调试中打印模板成员函数返回的值

如何在HTML中的不同模式中显示不同的值

如何在Python中打印模块文档

如何在Word 2007模板中打印模板行?

如何在 C++ 中打印模板类型名?

如何在 Python 中打印模块名称?

如何仅将某些字段插入到 hive 表中,重用现有的表架构?

使用'for'循环在Python中打印模式

C#中的打印模式

使用循环在 C 中打印模式

检测是否处于打印模式或单击数据表导出工具中的“打印”按钮

如何将数据从JSON显示到html表中

如何在不打印数组的情况下打印模型数据?

如何在Turbo C ++的图形模式下打印变量的值?

如何在查询中的某些条件下将字段值更改为空?

打印模式命令

如何在Wikipedia表中的列下打印所有值?

在打字稿中单击内联编辑按钮时如何打印对象的字段值

如何在 Julia 中显示字段值

如何在输入字段中显示值

如何使用Karate UI在Chrome中查看打印模式