JavaScript学习
2013-12-20 00:00
225 查看
js 打印指定区域
方法一:
<script language="javascript" type="text/javascript">
function printpage(myDiv){
//var newstr = document.all.item(myDiv).innerHTML;
var newstr = document.getElementById(myDiv).innerHTML;
alert(newstr);
var oldstr = document.body.innerHTML;
document.body.innerHTML = newstr;
window.print();
document.body.innerHTML = oldstr;
return false;
}
</script>
<div id="myDiv" >说明:打印整个div区域的内容,如果包含按钮,则按钮也会打印出来!
<div>
打印内容打印内容打印内容打印内容打印内容打印内容打印内容打印内容
adfhioasdhfiohasdofihosdhfosdhfiosdhfiosdfhsdfhsdifsidfiosdfhosdhf
</div>
<input type="button" id="bt" onclick="javascript:printpage('myDiv')" value="打印" />
</div>
方法二:
<script language="javascript" type="text/javascript">
function doPrint() {
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
}
</script>
<div>
<!--startprint-->说明:这是开始打印的位置
打印内容打印内容打印内容打印内容打印内容打印内容打印内容打印内容
adfhioasdhfiohasdofihosdhfosdhfiosdhfiosdfhsdfhsdifsidfiosdfhosdhf
<!--endprint-->说明:这是结束打印的位置
</div>
<input type="button" id="bt" onclick="javascript:doPrint()" value="打印" />
</div>
方法一:
<script language="javascript" type="text/javascript">
function printpage(myDiv){
//var newstr = document.all.item(myDiv).innerHTML;
var newstr = document.getElementById(myDiv).innerHTML;
alert(newstr);
var oldstr = document.body.innerHTML;
document.body.innerHTML = newstr;
window.print();
document.body.innerHTML = oldstr;
return false;
}
</script>
<div id="myDiv" >说明:打印整个div区域的内容,如果包含按钮,则按钮也会打印出来!
<div>
打印内容打印内容打印内容打印内容打印内容打印内容打印内容打印内容
adfhioasdhfiohasdofihosdhfosdhfiosdhfiosdfhsdfhsdifsidfiosdfhosdhf
</div>
<input type="button" id="bt" onclick="javascript:printpage('myDiv')" value="打印" />
</div>
方法二:
<script language="javascript" type="text/javascript">
function doPrint() {
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
}
</script>
<div>
<!--startprint-->说明:这是开始打印的位置
打印内容打印内容打印内容打印内容打印内容打印内容打印内容打印内容
adfhioasdhfiohasdofihosdhfosdhfiosdhfiosdfhsdfhsdifsidfiosdfhosdhf
<!--endprint-->说明:这是结束打印的位置
</div>
<input type="button" id="bt" onclick="javascript:doPrint()" value="打印" />
</div>
相关文章推荐
- 学习流行的JavaScript框架20120801-[jQuery,Dojo,MooTools]
- JavaScript学习
- Javascript学习笔记 基础(一)
- javascript 学习总结 1
- 如何从源码中学习javascript
- 【JS学习笔记】04 JavaScript 表单验证
- 说说掌握JavaScript语言的思想前提想学习js的朋友可以看看
- javascript基础学习--HTML DOM
- 从零学习JAVASCRIPT — 1、JavaScript 基础一
- JavaScript精简学习3:图像
- 前段学习之路-----javaScript
- Javascript性能优化学习笔记1
- 近期学习javascript和jquery遇到一些问题的技巧知识总结
- Javascript学习心得
- Javascript 学习书 推荐
- javascript之事件学习(一)
- Javascript学习7 - 脚本化浏览器窗口
- javascript学习笔记(4)--with和for(in)对象语句
- (5)JavaScript学习笔记 - 变量
- JavaScript学习--Item37 面向对象高级程序设计