javascript - 如何使用 javascript 或 jquery 打印表格中的特定列

标签 javascript php

有没有办法排除表中的列?我有一个表格,其中包含我想在打印过程中排除的每一行的选项。

 <table class="table table-hover table-bordered" style = "position : relative;    left : 0px; top : 0px; width : 100%; height : 10%" id = "tableitems">
 <thead>
        <th><center>ID</center> </th>
        <th><center>Item Name</center> </th>
        <th><center>Brand</center> </th>
        <th><center>Initial Price</center> </th>
        <th><center>Sales Price</center> </th>
        <th><center>Quantity</center> </th>
        <th><center>Dealer</center> </th>
        <th><center>Edit</center> </th>
        <th><center>Order</center> </th>
        <th><center>Defective</center> </th>
   </tr>
</thead>
<tbody>
    <?php
    foreach($rows as $row){
        if($row["Quantity"] < 10){
            print "<tr style = 'background-color : crimson; color : black' >";
        }else if($row["Quantity"] < 20) {
            print "<tr style = 'background-color : yellow; color : black' >";
        }else{
        }
print "<td>" . $row['ID'] . "</td>";
print "<td>" . $row['ItemName'] . "</td>";
print "<td>" . $row['Brand'] . "</td>";
print "<td>" . $row['InitialPrice'] . "</td>";
print "<td>" . $row['SalesPrice'] . "</td>";
print "<td>" . $row["Quantity"] . "</td>";
print "<td>" . $row["Dealer"] . "</td>";
print "<td><a href='Update.php?id=" . $row["ID"] . "'>Edit</a></td>";
print "<td><a href = '#!' onclick='show_overlay(" . $row['ID'] . ")'>Order</a></td>";
print "<td><a href = '#!' onclick='reorder(" . $row['ID'] . ")'>Defective</a></td>";
print "</tr>";
}
?>
</tbody>

我有这个让表格值出现问题的打印件,它是否还包括表格中的选项,是否无论如何要将某些列排除在表格中?

 <script>   
 function printData(){
 var divToPrint=document.getElementById("tableitems");
 newWin= window.open("");
 newWin.document.write("<center><h1>Meng and Mher</h1><p>List of Items</p> </center>");
 newWin.document.write(divToPrint.outerHTML);
 newWin.print();
 newWin.close();
 }

 $('btnprint').on('click',function(){
 printData();
 })
 </script>

最佳答案

您可以添加一行以将 css 打印到新窗口中以隐藏第 n 列,如下所示

newWin.document.write("<style> td:nth-child(2){display:none;} </style>");

关于javascript - 如何使用 javascript 或 jquery 打印表格中的特定列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35393053/

相关文章:

javascript - AngularJS - 如何强制范围输入的 ng-model 为空?

javascript - 如何将 ↵ 替换为\n

javascript - 夹线时插入阅读更多按钮

javascript - 如何使图像显示在容器 Div 内?

php - 单击导航栏中的选项时更改 $sql

php - 如何使用SSH导入mysql数据库中一张表中的大尺寸(10GB)数据?

PHP-数据库列数据查询返回另一列数据

java - 如果我将浏览器 cookie 复制到另一台电脑上,会发生什么情况?

php - 多个 PHP MySQL 插入

javascript - 如何判断用户是否真的在看网页?