我已经使用HTML和PHP创建了一个从数据库读取数据的表。表格的每个单元格显示不同的值,如1、2、3,并根据该值更改单元格的颜色。

到目前为止,我已经做到了这一点,并使用以下JavaScript对单元格进行条件格式设置:
脚本:
<script type="text/javascript">
$(function() {
$('#table1 td').each(function() {
if ($(this).text() == '1') {
$(this).css('background-color', 'red');
}
if ($(this).text() == '2') {
$(this).css('background-color', 'yellow');
}
if ($(this).text() == '3') {
$(this).css('background-color', 'green');
}
});
});
</script>现在我想用print Div打印表。打印选项也工作得很好,但是没有与单元格相关联的颜色,都是黑白的。我找了很多,但到目前为止没有找到任何解决方案。我真的需要你的帮助,任何建议或代码将非常感谢。
发布于 2019-01-28 21:44:05
尝试设置color-adjust: exact; (+,带chrome前缀)- Browser support for color-adjust
发布于 2019-01-28 21:45:43
默认情况下,浏览器不打印背景色,尝试添加<style type="text/css"> @media print { body { color-adjust: exact; } } </style>
此外,在Chrome的打印对话框窗口中的“更多设置”下有一个复选框,也可以打印BG颜色参见图像:

发布于 2019-01-28 21:56:00
@media print{
background-color: green;
//do the same for each other styles you need to print
}
https://stackoverflow.com/questions/54402774
复制相似问题