javascript 웹 페이지 의 특정 내용 인쇄(table 인쇄 를 예 로 들 면)

20604 단어 Web
    :
http://stackoverflow.com/questions/21375398/how-to-print-table-using-javascript
http://stackoverflow.com/questions/2555697/window-print-not-working-in-ie


/span>html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>      title>
head>

<body>
    <input type="button" id="print" value="  "/>
    <table border="1" cellpadding="3" id="printTable" >
        <tbody><tr>
            <th>First Nameth>
            <th>Last Nameth>
            <th>Pointsth>
        tr>
        <tr>
            <td>Jilltd>
            <td>Smithtd>
            <td>50td>
        tr>
        <tr>
            <td>Evetd>
            <td>Jacksontd>
            <td>94td>
        tr>
        <tr>
            <td>Johntd>
            <td>Doetd>
            <td>80td>
        tr>
        <tr>
            <td>Adamtd>
            <td>Johnsontd>
            <td>67td>
        tr>
        tbody>
    table>

    <script>
        window.onload = function()
        {
            var btnPrint = document.getElementById("print");//“  ”  
            btnPrint.onclick = function()// “  ”        
            {
                printTable();//    
            }
        }

        //    
        function printTable()
        {
            var tableToPrint = document.getElementById('printTable');//        
            var newWin= window.open("");//        
            newWin.document.write(tableToPrint.outerHTML);//          
            newWin.document.close();// IE             
            newWin.focus();// IE             

            newWin.print();//  
            newWin.close();//    
        }
    script>
body>
html>

좋은 웹페이지 즐겨찾기