js打印表格内容

来源:互联网 发布:青少年儿童 vb可以吃 编辑:程序博客网 时间:2024/05/19 17:25
function printTable()
        {
        bdhtml=window.document.body.innerHTML;
         sprnstr="<!--startprint-->";//必须在页面添加<!--startprint-->和<!--endprint-->而且需要打印的内容必须在它们之间
         eprnstr="<!--endprint-->";
         prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
         prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
         var newwin = window.open("");
         var css="<style>table{width: 100%; text-align: left; border-collapse: collapse; background: #fff; font: 16px '微软雅黑'; color:#333;}"
         +"table tr{height: 60px;}"
         +"table tr:first-child{height: 46px;}"
         +"table tr:nth-child(2n+1){background-color: #eef3f9;}"
         +"table tr:hover{background: #1099c0; color: #fff;}"
         +"table th{-height: 46px; color: #fff; background-color: #1099c0;text-align: left;}"
         +"table th:first-child{width: 5%;}"
         +"table td{height: 60px;} "
         +"table td:last-child{color: #1bcd94;}"
         +"table td.notEnabled{color: #ff6d46;}"
         +"table div{width: 16px; height: 16px; border: 1px solid #959595; margin: 0 auto; background: #fff;}"
         +"table div.current{background: url(../img/gou2.png) center no-repeat #fff;}</style>"
         newwin.document.body.innerHTML=css+prnhtml;
         newwin.print();         
        }
原创粉丝点击