个人小说网站友书-绿色、纯净、无广告欢迎广大同行前来指点、阅读
话不多说,直接上代码,
function Print(data) {
$.post("../../program/ashx/PrintAshx.ashx", { Id: data, OrderId: $("#HiddenField1").val() }, function (data) {
if (data != "" && data != null && data != undefined) {
var head = "<html><head><title></title></head><body><OBJECT classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2' height='0' id='WebBrowser3' width='0' VIEWASTEXT></OBJECT><div align='center'><table width=250px align='center'>";//先生成头部
var foot = "</table></div></body></html>";//生成尾部
var newstr = "";
newstr += '<tr><td colspan="4" style="font-size:10px;line-height:20px">单据编号:' + data["djbh"] + '</td></tr>';
newstr += '<tr><td colspan="4" style="font-size:10px;line-height:20px">机构:' + data["jigou"] + '</td></tr>';
newstr += '<tr><td colspan="4" style="font-size:10px;line-height:20px">中心:' + data["center"] + '</td></tr>';
newstr += '<tr><td colspan="4" style="font-size:10px;line-height:20px" align="left">-------------------收款清单-------------------</td></tr>'
newstr += '<tr><td style="font-size:10px" colspan="4">付款人:' + data["fukuan"] + ' ' + "\t\t\t" + '打印时间:' + data["sysdt"] + '</td></tr>';
newstr += '<tr><td style="font-size:10px" colspan="4">------------------------------------------------</td></tr>';
newstr += '<tr><td style="font-size:10px" style="width:20%" align="center"></br>序号</td><td style="width:40%;font-size:10px" align="center">项目</td><td style="width:20%;font-size:10px" align="center">数量</td><td style="width:20%;font-size:10px" align="center">金额</td></tr>';
newstr += '<tr><td style="font-size:10px" style="width:20%;font-size:10px" align="center">' + data["xh"] + '</td><td style="width:50%;font-size:10px" align="center">' + data["item"] + '</td><td style="width:10%;font-size:10px" align="center">' + data["shuliang"] + '</td><td style="width:20%;font-size:10px" align="center">' + data["zongjia"] + '</td></tr>';
newstr += "<tr></tr>" + data["youhui"];
newstr += '<tr><td style="font-size:10px" colspan="4"></br>应付合计:' + data["yingfu"] + '</td></tr>';
newstr += '<tr><td style="font-size:10px" colspan="4"></br>支付金额:' + data["shifu"] + '</td></tr>';
newstr += '<tr><td style="font-size:10px" colspan="4"></br>支付时间:' + data["sysdt"] + '</td></tr>';
newstr += '<tr><td style="font-size:10px" colspan="4"></br>------------------------------------------------</td></tr>';
newstr += '<tr><td style="font-size:10px" colspan="4">收款人:' + data["username"] + '</td></tr>';
newstr += '<tr><td style="font-size:10px" colspan="4">------------------------------------------------</td></tr>';
newstr += '<tr><td style="font-size:10px" colspan="4"></br>备注:此单为缴款凭证,请妥善保存</td></tr>';
newstr += '<tr><td style="font-size:10px" colspan="4"></br>联系电话:' + data["tel"] + '</td></tr>';
newstr += '<tr><td style="font-size:10px" colspan="4"></br>地址:' + data["dizhi"] + ' </td></tr>';
----------------------------以上内容为拼接要打印的html页面------------------
var oldstr = document.body.innerHTML;//获取原本网页页面代码
document.body.innerHTML = head + newstr + foot;//拼接打印页面
if (getExplorer() == "IE") {//判断是否IE浏览器,是,调用去除页眉页脚的方法,否,直接输出即可
pagesetup_null();
}
window.print();
document.body.innerHTML = oldstr;//还原网页;
return false;
}
}, "Json");
}
function pagesetup_null() {
var hkey_root, hkey_path, hkey_key;
hkey_root = "HKEY_CURRENT_USER";
hkey_path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
try {
var RegWsh = new ActiveXObject("WScript.Shell");
hkey_key = "header";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "");
hkey_key = "footer";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "");
} catch (e) { }
}
function getExplorer() {
var explorer = window.navigator.userAgent;
//ie
if (explorer.indexOf("MSIE") >= 0) {
return "IE";
}
//firefox
else if (explorer.indexOf("Firefox") >= 0) {
return "Firefox";
}
//Chrome
else if (explorer.indexOf("Chrome") >= 0) {
return "Chrome";
}
//Opera
else if (explorer.indexOf("Opera") >= 0) {
return "Opera";
}
//Safari
else if (explorer.indexOf("Safari") >= 0) {
return "Safari";
}
}
结果截图展示:
如有问题,请加我QQ:631931078或352167311