博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
js实现局部打印及其打印预览
阅读量:4212 次
发布时间:2019-05-26

本文共 1476 字,大约阅读时间需要 4 分钟。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="WebApplication2.Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ">
<html xmlns=" ">
<head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript">
        function printdiv() {
            var newstr = document.getElementById("PrintContentDiv").innerHTML;   //获得需要打印的内容
            // alert(newstr);
            var oldstr = document.body.innerHTML;   //保存原先网页的代码
            document.body.innerHTML = newstr; //将网页内容更改成需要打印
            window.print();
            document.body.innerHTML = oldstr;   //将网页还原
            return false;
        }
        //打印页面预览
        function printpreview() {
            var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
            document.getElementById("divButton").style.display = "none";//隐藏打印及其打印预览页面
            document.body.insertAdjacentHTML('beforeEnd', WebBrowser); //在body标签内加入html(WebBrowser activeX控件)
            WebBrowser1.ExecWB(7, 1); //打印预览
        }
        
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="PrintContentDiv">
        序号总和:15<br />
        年龄总和:109<br />
        成绩总和:413<br />
        序号年龄成绩总和112<br />
        序号年龄成绩总和104<br />
        序号年龄成绩总和93<br />
        序号年龄成绩总和115<br />
        序号年龄成绩总和113<br />
        序号 姓名 年龄 学号 成绩<br />
        1 田 23 XH001 88<br />
        2 笑 22 XH002 80<br />
        3 高 20 XH003 70<br />
        4 汗 21 XH004 90<br />
        5 敏 23 XH005 85<br />
    </div>
    <div id="divButton">
        <input type="button" οnclick="printdiv()" value="打 印" /><br />
        <input type="button" οnclick="printpreview()" value="打印预览" />
    </div>
    </form>
</body>
</html>

转载地址:http://sxzmi.baihongyu.com/

你可能感兴趣的文章
【unix网络编程第三版】阅读笔记(二):套接字编程简介
查看>>
【一天一道LeetCode】#115. Distinct Subsequences
查看>>
【一天一道LeetCode】#116. Populating Next Right Pointers in Each Node
查看>>
【一天一道LeetCode】#117. Populating Next Right Pointers in Each Node II
查看>>
【一天一道LeetCode】#118. Pascal's Triangle
查看>>
同步与异步的区别
查看>>
IT行业--简历模板及就业秘籍
查看>>
JNI简介及实例
查看>>
JAVA实现文件树
查看>>
linux -8 Linux磁盘与文件系统的管理
查看>>
linux 9 -文件系统的压缩与打包 -dump
查看>>
PHP在变量前面加&是什么意思?
查看>>
ebay api - GetUserDisputes 函数
查看>>
ebay api GetMyMessages 函数
查看>>
php加速器 - zendopcache
查看>>
手动12 - 安装php加速器 Zend OPcache
查看>>
set theme -yii2
查看>>
yii2 - 模块(modules)的view 映射到theme里面
查看>>
yii2 - controller
查看>>
yii2 - 增加actions
查看>>