js 打印指定页面部分打印
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
function do_print(id_str){
//id-str 打印区域的id
var el = document.getElementById(id_str);
var iframe = document.createElement('IFRAME');
var doc = null;
iframe.setAttribute('style','position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
document.body.appendChild(iframe);
doc = iframe.contentWindow.document;
// 引入打印的专有CSS样式,根据实际修改
//doc.write("<LINK rel=\"stylesheet\" type=\"text/css\" href=\"css/print.css\">");
doc.write('<div>' + el.innerHTML + '</div>');
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();
if (navigator.userAgent.indexOf("MSIE") > 0){
document.body.removeChild(iframe);
}
}
</script>
</head>
<body>
<!--打印区域: -->
<div id="print_box">
<div style="width: 500px; height: 500px; border: 5px solid #6b3906;">
<h1>hello kitty!</h1>
</div>
</div>
<!--// 调用打印 -->
<button onclick="javascript:do_print('print_box');">打印</button>
</body>
</html>
实战项目中的使用
$scope.do_print = function (id_str) {
//id-str 打印区域的id
var el = document.getElementById(id_str);
var iframe = document.createElement('IFRAME');
var doc = null;
iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
document.body.appendChild(iframe);
doc = iframe.contentWindow.document;
// 引入打印的专有CSS样式,根据实际修改
//doc.write("<LINK rel=\"stylesheet\" type=\"text/css\" href=\"css/print.css\">");
if ($scope.orderinfo.inv==null) {
var txt = "table{border-collapse:collapse;border-spacing:0;border-left:1px solid #000000;border-top:1px solid #000000;} td{border: 1px solid #000000;}th{border: 1px solid #000000;}#changefapiao{visibility: hidden;} .change{border-right: 0px solid #000000;}.change1{border-left: 0px solid #000000;} .title{text-align:center;} #fapiao{display:none;}";
}
else {
var txt = "table{border-collapse:collapse;border-spacing:0;border-left:1px solid #000000;border-top:1px solid #000000;} td{border: 1px solid #000000;}th{border: 1px solid #000000;}#changefapiao{visibility: hidden;} .change{border-right: 0px solid #000000;}.change1{border-left: 0px solid #000000;} .title{text-align:center;}";
}
doc.write('<style>' + txt + '</style>');
doc.write('<body>' + el.innerHTML + '</body>');
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();
if (navigator.userAgent.indexOf("MSIE") > 0) {
document.body.removeChild(iframe);
}
}
最新文章
- JS入门学习,写一个时钟~
- yyyy-MM-dd与YYYY-MM-dd
- img图片下面出现莫名的下边距解决办法
- SQL内联多个表
- 调用webservice 417
- undo损坏故障恢复(二)ORA-01092,ORA-00604,ORA-01110
- 【转】V4L2+swscale+X264+live555实现流媒体服务端
- iscroll5 版本下的 上拉,下拉 加载数据
- Memcached&#183;Redis缓存的基本操作
- 数据库索引------Hash索引的使用限制
- Linux 安装多个版本JDK并设置默认版本
- Unity---在Hierarchy视图中将选中的对象的层级目录复制到剪切板
- jenkins 构建到最后报权限的问题
- Java二叉树的实现与特点
- jvm--深入理解java虚拟机 精华总结(面试)(转)
- mac burp suite https证书安装
- Bash数组
- ERROR 1045 (28000): Access denied for user &#39;hive&#39;@&#39;localhost&#39; (using password: YES)
- Tensorflow BatchNormalization详解:1_原理及细节
- GC之八--GC 触发Full GC执行的情况及应对策略
热门文章
- 工作中的Buff加成-结构化思考力:自创独门武功 3-3-3原则
- C#生成二维码(加源码)
- C++的可移植性和跨平台开发
- “全栈2019”Java第七十五章:内部类持有外部类对象
- Python常用功能函数
- Azure File挂载报错--System Error 1231
- python为何需要虚拟环境--Python虚拟环境的安装和配置-virtualenv
- fetch 请求列表ListView
- javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection timed out: connect
- ${__BeanShell(${SCRIPT})}