当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How i can print report without first column of table

问题描述:

I want to print some reports in my project my problem is printing report format you can get some idea from links. Now i print div but I want to print first column hide while printing

this is now i print

I want this format

<script language="javascript" type="text/javascript">

function printDiv(divID)

{

//Get the HTML of div

var divElements = document.getElementById(divID).innerHTML;

//Get the HTML of whole page

var oldPage = document.body.innerHTML;

//Reset the page's HTML with div's HTML only

document.body.innerHTML =

"<html><head><title></title></head><body>" +

divElements + "</body>";

//Print Page

window.print();

//Restore orignal HTML

document.body.innerHTML = oldPage;

}

</script>

网友答案:

See css media types. You can define css rules that will be applied while printing, ex:

@media print {
    tr.firstRow {
        display: none;
    }
}
网友答案:

Try this

@media print {
 table tr:first-child{
        display: none;
    }
}
网友答案:

By using the media query in css:

@media print{
    /* and here everything you want print only */
    table tr:first-child{
        display: none;
    }
}

Bare in mind: first-child doesnt always work, its an example. You could give it a class and use that This doesnt work very well in IE8 and lower, not sure about IE9. You can also do this:

<link rel="stylesheet" href="print_only.css media="print" />

You place that in the head of your page.

网友答案:
<script language="javascript" type="text/javascript">
                        function printDiv(divID)
                         {
                            //Get the HTML of div
                            var divElements = document.getElementById(divID).innerHTML;
                            //Get the HTML of whole page
                            var oldPage = document.body.innerHTML;

                            //Reset the page's HTML with div's HTML only
                            document.body.innerHTML = 
                            "<html><head><title></title></head><body>" + 
                            divElements + "</body>";

                            //Print Page
                            window.print();

                            //Restore orignal HTML
                            document.body.innerHTML = oldPage;

                        }
                 </script>
                 <div id="dd">shafi</div>
                 <div onClick="printDiv('dd');">print</div>
网友答案:

Try this,

$('table tr:first').hide();

before

//Print Page
window.print();

To Hide all first columns try,

$('table tr td:eq(0)').hide();
分享给朋友:
您可能感兴趣的文章:
随机阅读: