js或jquery实现页面打印(局部打印) 1、js实现(可实现局部打印) 代码如下:<html> <title>js打印</title> <head></head><body> <input id="btnPrint" type="button" value="打印" onclick="javascript:window.print();" /> <input id="btnPrint" type="button" value="打印预览" onclick=preview(1) /> <style type="text/css" media=print> .noprint{display : none } </style> <p class="noprint">不需要打印的地方</p> <script...
本文主要内容: 如果用浏览器自带的打印按钮,无法进行其余和打印相关的操作,如传递打印次数等等。所以需要把浏览器打印的功能保留并赋予到自己添加的按钮当中,可以在点击按钮的同时触发自定义的函数。 代码如下:<input type="button" class="btnPrint" id="btnPrint" value="打印" /> <iframe frameborder=0 width="100%" height="400px" id="printPDFIframe" src=""<span style="white-space:pre"> </span>></iframe> 代码如...
代码如下:function preview(oper) { if (oper < 10) { bdhtml = window.document.body.innerHTML;//获取当前页的html代码 sprnstr = "<!--startprint" + oper + "-->";//设置打印开始区域 eprnstr = "<!--endprint" + oper + "-->";//设置打印结束区域 prnhtml = bdhtml.substring(bdhtml.indexOf(sprnstr) + 18); //从开始代码向后取html prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));//从结束代码向前取html windo...
在一些要求不是很高的小项目中,可以使用一些虽不是通用且不是新技术但是确实可以很好实现功能的技术来实现这些功能。这样系统不是显示的很复杂,且可以方便维护。 新建一个exportPrint.html页面,里面的代码如下所示,就可以实现导出到Excel和打印网页。代码如下:<html> <head> <title>IE浏览器使用JS技术导出到Excel和打印</title> <style> .table_stat { border-right:0px; border-bottom:0px; border-left:1px so...
1、程序说明1) 此程序可以实现选择页面中的区域进行打印,以iframe方式进行打印;2) 与原生态的print() 区别在于,取消打印页面后可以完整保留当前访问页面的内容。2、代码部分 1) JS 函数:代码如下: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;l...
代码如下:<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD> <TITLE>javascript打印-打印页面设置-打印预览代码</TITLE> <META http-equiv=Content-Type content="text/html; charset=gb2312" /> <style media=print> .Noprint{display:none;} .PageNext{page-bre...
今天要做一个打印网页的小功能,直接调用window.print(),但是打印出来后,字体总是缩小一号,找不到原因。。。 后来尝试用一个IE的打印控件,但仅支持ie有点恶心,只能返回去继续找原因 原来,我要打印的页面因为是哥弹出层,所以出现这种现象,后来直接target="_blank",就可以正常打印了。 另外, 代码如下:function preview() { bdhtml=window.document.body.innerHTML; sprnstr="<!--startprint-->"; eprnstr="<!--endprint-...
1. 用media="print"的css来控制要打印的文件testPrint.html中引用media为print的样式,表示打印时该样式才起作用 代码如下:<link href="/style/print.css" rel="stylesheet" type="text/css" media="print"> /style/print.css文件 代码如下:.noprint{display:none;} 在testPrint.html中使用print.css中的样式,在网页浏览的时候是看不出效果的,但是打印的时候会起作用,如下面这一段,加上noprint之后,在浏览器中仍然是现实的...
代码如下:<html> <head> <title></title> <script> /* //声明时间 var date = new Date(); alert(date);//当前时间 alert(date.toLocaleString());//转化为本地时间 alert(date.getFullYear());//显示年份 alert(date.getMonth() + 1);//显示月份 0-11,需要加1 alert(date.getDate());//显示一月中的日期 alert(date.getDay());//显示一周的日期,星期几 alert(date.getHours());//获取小时时间 alert(date.getMinutes());//获取当...
首先我们可以把要打印的内容放在div中,然后用下面的代码进行打印。代码如下:<html><head><script language="javascript">function printdiv(printpage){var headstr = "<html><head><title></title></head><body>";var footstr = "</body>";var newstr = document.all.item(printpage).innerHTML;var oldstr = document.body.innerHTML;document.body.innerHTML = headstr+newstr+footstr;window.print(); document.body.innerHTM...
代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <div id="divPrint"> <table> <tr><td>我的打印的内容</td></tr> </table> </div> <p>所有内容</p> <a href="javascript:printme()" tar...
我们知道javascript可以用alert输出变量的值,但是有时候返回的是一个对象,json格式的数据,jQuery可以用这个方法循环遍历读出对象的值,假如这个对象名称是obj,循环遍历打印它的值: 代码如下: $.each(obj,function(key,val){ if($.isPlainObject(val) || $.isArray(val)){ subObj(val); }else{ alert(key+'='+val); } });
代码如下:<!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><script type="application/javascript" src="jquery.js"></script><title>企业培训,it培训,数据库培训,android培训,嵌入式培训</title></head>...
最近做到了web页面课程表打印时,上网找了一些资料,最后使用了下面的方法实现了我需要的功能。将需要打印的课程表的table放入div标签中,然后指定出需要打印的区域,最后调用window.print打印指定内容。 示例代码(代码中有些内容已省略) 代码如下:function preview() { bdhtml = window.document.body.innerHTML; sprnstr = "<!--startprint-->"; eprnstr = "<!--endprint-->"; prnhtml = bdhtml.substr(bdhtml.ind...
代码如下:input type="button" onclick="document.execCommand(open)" value=打开 input type="button" onclick="document.execCommand(saveas)" value=保存 input type="button" onclick="document.execCommand(print)" value=打印 input type="button" onclick="document.execCommand(selectall)" value=全选 input type="button" onclick="location.replace(view-source:+location)" value=源文件 input type="button" onclick=...