有没有办法排除表中的列?我有一个表格,其中包含我想在打印过程中排除的每一行的选项。
<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/