简体   繁体   English

如何在jQuery PrintArea中传递自定义html标记

[英]How to pass a custom html tag in jQuery PrintArea

I use the Jquery function printarea to print a part of my page (some columns of a table). 我使用Jquery函数printarea打印页面的一部分(表的某些列)。

If I place the selector class in the two columns I need to print, like this: 如果将选择器类放置在需要打印的两列中,如下所示:

<tr>
  <td class="printarea">content1</td>
  <td class="printarea">content2</td>
  <td>content3</td>
</tr>    

The function will print each column in one row: 该函数将在每一行中打印每一列:

content 1 content 2

If I place the selector class to the tr instead, like this: 如果我将选择器类放到tr ,如下所示:

<tr class="printarea">

It prints every column in one single row: 它在一行中打印每一列:

content 1 content 2 content 3

What I need is to print the two first columns in one row: 我需要在一行中打印前两列:

content 1 content 2

Does anyone know how to achieve this? 有谁知道如何实现这一目标?

First of all hide all the rows in the table then show only two columns in the row using :lt selector in jquery. 首先,隐藏表中的所有行,然后在jquery中使用:lt选择器仅显示该行中的两列。 it displays first two columns in the below context 它在以下上下文中显示前两列

$("table tr td").hide();
$("table tr td:lt(2)").show();

FIDDLE 小提琴

This will work, Use Colgroups, don't need to use jquery, Is there a specific reason you want JS/Jquery ? 这将起作用,使用Colgroups,不需要使用jquery,是否有特定的原因想要JS / Jquery?

 .printable{background-color:red;} .notprintable{background-color:yellow;} @media print{ .notprintable{display:none} } 
 <table> <colgroup> <col span="2" class="printable"> <col class="notprintable"> </colgroup> <thead><tr><th>print 1 head</th><th>print 2 head</th><th>none print head</th></tr></thead><tbody><tr><td> print</td><td>print</td><td> no print</td></tr><tr><td> print</td><td>print</td><td> no print</td></tr><tr><td> print</td><td>print</td><td> no print</td></tr></tbody><tfoot><tr><td> print</td><td>print</td><td> no print</td></tr></tfoot></table> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM