js最简单的代码实现局部打印功能(非插件)

820 ℃

javascript用最简单的代码实现局部打印功能,下面web建站小编给大家简单介绍一下实现代码!

html代码:

复制代码<p id="print1">打印当前区域1</p>
<p id="print2">打印当前区域2</p>
<button onclick="printer1()">打印区域1</button>
<button onclick="printer2()">打印区域2</button>
  • 1
  • 2
  • 3
  • 4

js代码:

复制代码//打印区域1
function printer1(){
  var newWin = window.open('printer', '', '');
  var print = document.getElementById("print1").innerText; //打印区域
  newWin.document.write(print);
  newWin.document.location.reload();
  newWin.print();
  newWin.close();
}

//打印区域2
function printer2(){
  var newWin = window.open('printer', '', '');
  var print = document.getElementById("print2").innerText; //打印区域
  newWin.document.write(print);
  newWin.document.location.reload();
  newWin.print();
  newWin.close();
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

jQuery实现网页div局部打印(jQuery.print插件)

javascript原生实现局部打印(兼容IE9)

jquery利用jqprint实现局部打印(兼容IE8)

jquery利用printArea实现局部打印和全局打印

javascript实现局部打印功能(兼容IE8)

标签: 局部打印

上面是“js最简单的代码实现局部打印功能(非插件)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_2881.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

vue如何利用v-for遍历二维数组
vue页面如何利用插件实现列表滚动循环
Python语法如何利用split分隔字符串
ArcoDesign一套Vue3/React UI 组件库中文文档官网介绍
css3实现模糊背景,内容清晰