网页打印(不使用插件的情况下)

//剔除不需要打印的部分
        function Contrarypreview() {
            bdhtml = document.body.innerHTML;
            sprnstr = "<!--startprint-->";
            eprnstr = "<!--endprint-->";
            var tophtml = bdhtml.substr(0, bdhtml.indexOf(sprnstr));
            var bothtml = prnhtml.substring(bdhtml.indexOf(eprnstr)+15);
            document.body.innerHTML = tophtml + bothtml;
            document.execCommand("print");
        }
function preview() {
            bdhtml = window.document.body.innerHTML;
            sprnstr = "<!--startprint-->";
            eprnstr = "<!--endprint-->";
            prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
            prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
            window.document.body.innerHTML = prnhtml;
            window.print();
        }```


已测试

function print4() {
var headhtml = document.getElementById(“head”).innerHTML;
//alert(headhtml);
var headstr = “” + headhtml + ““;
var footstr = ““;
var printData = document.getElementById(“dvData”).innerHTML; //获得 div 里的所有 html 数据
var oldstr = document.body.innerHTML;
document.body.innerHTML = headstr + printData + footstr;
//window.print();
document.execCommand(“print”);
//document.body.innerHTML = oldstr;
return false;
}



function print2() {
document.execCommand(“print”);
}
function print3() {
window.print();
}



----------

function print5() {
(‘#Div1’).attr(“style”,”display:none;”);  
            document.execCommand(“print”);
(‘#Div1’).attr(“style”, “display:block;”);
}
“`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值