douyin6188 2019-01-28 13:11
浏览 325

打印具有条件格式的表格单元格背景颜色

I have created a table using HTML and PHP that reads the data from the database. Each cell of the table displays different values like 1,2,3 and based on the value the colors of the cells are changed. I have managed to do it so far, and used the following JavaScript for the conditional formatting of the cells:

Script:

<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>

Now I want to print the table with print Div. print option is working fine as well, however there is no color associated with the cells, its all black and white. I searched a lot but could not find any solution so far. I really need your help, and any suggestions or codes will be highly appreciated.

  • 写回答

3条回答 默认 最新

  • doucanshou6998 2019-01-28 13:44
    关注

    Try to set color-adjust: exact; (+with prefix for chrome) - Browser support for color-adjust

    评论

报告相同问题?