关于MVC打印问题,打印指定的内容
首先你的内容一定要放在一个div中如下代码
<div id="divprint">
<table class="table table-striped dataTable table-bordered" id="DataTables_Table_0" aria-describedby="DataTables_Table_0_info">
<thead>
<tr role="row">
<th class="sorting_asc" role="columnheader" tabindex="" aria-controls="DataTables_Table_0" rowspan="" colspan="" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending" style="width: 140px;">用户名ID</th>
<th class="sorting" role="columnheader" tabindex="" aria-controls="DataTables_Table_0" rowspan="" colspan="" aria-label="Browser: activate to sort column ascending" style="width: 180px;">用户名</th>
<th class="sorting" role="columnheader" tabindex="" aria-controls="DataTables_Table_0" rowspan="" colspan="" aria-label="Platform(s): activate to sort column ascending" style="width: 160px;">电话</th>
<th class="sorting" role="columnheader" tabindex="" aria-controls="DataTables_Table_0" rowspan="" colspan="" aria-label="Engine version: activate to sort column ascending" style="width: 140px;">真实姓名</th>
<th class="sorting" role="columnheader" tabindex="" aria-controls="DataTables_Table_0" rowspan="" colspan="" aria-label="CSS grade: activate to sort column ascending" style="width: 140px;">工号</th>
<th class="sorting" role="columnheader" tabindex="" aria-controls="DataTables_Table_0" rowspan="" colspan="" aria-label="CSS grade: activate to sort column ascending" style="width: 167px;">拥有角色</th>
</tr>
</thead> <tbody role="alert" aria-live="polite" aria-relevant="all">
@foreach (var item in Model.EntityList)
{
<tr>
<td class=" sorting_1">@item.OneUser.Uid</td>
<td class=" ">@item.OneUser.UserName</td>
<td class=" ">@item.OneUser.Tel</td>
<td class=" ">@item.OneUser.TrueName</td>
<td class=" ">@item.OneUser.WorkNo</td>
<td class=" ">
@if (item.HasRole!=null&&item.HasRole.Count>)
{
foreach (var name in item.HasRole)
{
<p>@name</p>
}
}
</td>
</tr>
} <tr class="odd">
<td class=" sorting_1">Gecko</td>
<td class=" ">Firefox 1.0</td>
<td class=" ">Win + / OSX.+</td>
<td class=" ">1.7</td>
<td class=" ">A</td>
</tr>
<tr class="even">
<td class=" sorting_1">Gecko</td>
<td class=" ">Firefox 1.5</td>
<td class=" ">Win + / OSX.+</td>
<td class=" ">1.8</td>
<td class=" ">A</td>
</tr>
</tbody>
</table>
</div>
<input type="button" id="btndy" value="打印" />
然后我们看JS代码部分:(注意:因为这里部分打印损坏了HTML代码结构,所以不管你打不打印都要重新加载当前页面,这里我们用window.location.href="/Account/UserManagerMent";或window.reload();)
$(function () {
$("#btndy").click(function () {
var headstr = "<html><head><title></title></head><body>";
var footstr = "</body>";
var newstr = $("#divprint").html(); // 获取要打印的div内容
var oldstr = document.body.innerHTML; // 将过去的body内容存到oldstr
document.body.innerHTML = headstr + newstr + footstr; // 组合打印内容
window.print(); // 弹出打印窗体
document.body.innerHTML = oldstr; // 还原HTML内容
window.location.href="/Account/UserManagerMent"; // 刷新当前页面
});
});
至于后台以前是什么样,现在还是什么样,只是刷新一下而已
小Y子的代码和我的差不多
<button onclick="doPrint()">打印</button>
<div id="pri">
111111111
</div>
<script>
function doPrint(){
var head_str = "<html><head><title></title></head><body>"; //先生成头部
var foot_str = "</body></html>"; //生成尾部
var older = document.body.innerHTML;
var new_str = document.getElementById('pri').innerHTML; //获取指定打印区域
var old_str = document.body.innerHTML; //获得原本页面的代码
document.body.innerHTML = head_str + new_str + foot_str; //构建新网页
window.print(); //打印刚才新建的网页
document.body.innerHTML = older; //将网页还原
return false;
}
</script>
关于MVC打印问题,打印指定的内容的更多相关文章
- 在ASP.NET2.0里打印网页指定的内容(比如打印网页里的一个Table)
原文:在ASP.NET2.0里打印网页指定的内容(比如打印网页里的一个Table) 打印指定内容: <html> <head> <script type= " ...
- HOW TO:使用 Visual C# .NET 打印 RichTextBox 控件的内容
概要 本分步指南介绍了如何打印 RichTextBox 控件的内容.RichTextBox 控件没有提供任何打印 RichTextBox 内容的方法.您可以扩展 RichTextBox 类以使用 EM ...
- C#如何打印RichTextBox控件的内容
本任务的内容 摘要 创建 RichTextBoxPrintCtrl 控件 测试控件 参考 概要 本分步指南介绍了如何打印 RichTextBox 控件的内容.RichTextBox 控件没有提供任 ...
- python 打印 str 字符串的实际内容 repr(str)
python 打印 str 字符串的实际内容 repr(str) s = 'aa' print(repr(s))
- C#实现打印与打印预览功能
C#实现打印与打印预览功能的思路及代码. 在windows应用程序中文档的打印是一项非常重要的功能,在以前一直是一个非常复杂的工作,Microsoft .Net Framework的打印功能都以组件的 ...
- C#教程之打印和打印预览
最近研究一了一下关于PDF打印和打印预览的功能,在此小小的总结记录一下学习过程. 实现打印和打印预览的方法,一般要实现如下的菜单项:打印.打印预览.页面设置. PrintDocument类 Print ...
- C#实现打印与打印预览功能(转)
在windows应用程序中文档的打印是一项非常重要的功能,在以前一直是一个非常复杂的工作,Microsoft .Net Framework的打印功能都以组件的方式提供,为程序员提供了很大的方便,但是这 ...
- python3获取指定目录内容的详细信息
不同平台获取指定目录内容的详细信息命令各不相同: Linux中可以通过ls -al获取获取 windows中可以通过dir命令获取 下面是我写的一个通用获取目录内容详细信息的python3脚本: #! ...
- 获取txt文件指定行内容
#!/usr/bin/python num=0; ni=open("C:\Python34\ceshi.txt") for line in ni: num=num+1; #表示行 ...
- android网页打印,安卓网页打印,h5页面打印,浏览器打印,js打印工具
Android设备打印比较麻烦,一般设备厂商都提供原生app开发的SDK,我们web开发者为难了,不会原生开发啊 给大家提供一个思路,实现web加壳,利用打印浏览器实现 简单来说就是把我们的web页面 ...
随机推荐
- [SCOI2010]序列操作[分块or线段树]
#include<cstdio> #include<iostream> #define lc k<<1 #define rc k<<1|1 using ...
- 如何让listview滚动到底部
方法一: // msgListView是ListView控件 // adapter是ListView绑定的Adapter,如果不方便直接使用,也可以通过ListView的getAdapter()方法获 ...
- vue 添加过滤器-以格式化日期为例
vue的filter和angular的pipe管道类似,是过滤器 官网:https://cn.vuejs.org/v2/guide/filters.html 添加格式化日期的全局过滤器 在main.j ...
- react-native 学习(三)
上一次讲到了react-native 的配置环境 和 如何去进行调试,这一次我们说一说,关于react-native的 样式兼容问题. 由于iphonex的发售,在兼容的时候,我门也需要去考虑ipho ...
- swift tableViewController
tableViewController 控制器 import UIKit class ViewController: UITableViewController { ...
- Truncate有外键约束的表
SET FOREIGN_KEY_CHECKS=0; TRUNCATE TABLE table_name; SET FOREIGN_KEY_CHECKS=1;
- 浏览器端js处理or直接冗余至服务器php处理?
w交给客户端浏览器js处理,减少向服务器的提交字节.精简处理逻辑.
- Spark源码分析 – SparkContext
Spark源码分析之-scheduler模块 这位写的非常好, 让我对Spark的源码分析, 变的轻松了许多 这里自己再梳理一遍 先看一个简单的spark操作, val sc = new SparkC ...
- idea破解方法
1.http://idea.lanyus.com/ 下载破解文件 2.将下载的JetbrainsIdesCrack-3.4-release-enc.jar破解文件放在idea安装目录下的bin中: 3 ...
- PHP 错误日志
display_errors 错误回显,一般常用语开发模式,但是很多应用在正式环境中也忘记了关闭此选项.错误回显可以暴露出非常多的敏感信息,为攻击者下一步攻击提供便利.推荐关闭此选项. display ...