积极答复者
一个网页打印执行区域问题

问题
-
代码如下.运行有错误
<!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=gb2312" />
<title>无标题文档</title>
<script language="JavaScript" type="text/JavaScript">
function DP() {
if (window.print)
{
var Div1 = document.all.Div1.innerHTML;
var Div2 = document.all.Div2.innerHTML;
var css = '<style type="text/css" media=all> p { line-height: 120%}
.ftitle { line-height: 120%;
.font-size: 18px; color: #000000}
td{ font-size: 10px; color: #000000}</style>';
var body1='<table width="640" border="0" cellspacing="0" cellpadding="5"><tr><td class="fbody"><div align="center" class=ftitle>'+ Div1 +'</div>'+ Div2 +'</td></tr></table>';
document.body.innerHTML = '<center>' + css + body1 + '</center>';
window.print();
//window.history.go(0);
}
}
</script><style>
@media print {
.noprint {display:none}
}
</style></head>
<body>
<div id="Div1" name="Div1">12345</div>
<div id="Div2" name="Div2">asdf</div>
<a href="javascript:void(0)" onclick="DP()">[打印简历]</a>
</body>
</html>
不用羡慕----那,只是个传说!- 已移动 Sheng Jiang 蒋晟 2009年9月4日 20:03 客户端脚本问题 (发件人:ASP.NET 与 AJAX)
答案
-
function DP() { if (window.print) { var Div1 = document.all.Div1.innerHTML; var Div2 = document.all.Div2.innerHTML; var css = '<style type="text/css" media=all> p { line-height: 120%} .ftitle { line-height: 120%; .font-size: 18px; color: #000000} td{ font-size: 10px; color: #000000}</style>'; var body1 = '<table width="640" border="0" cellspacing="0" cellpadding="5"><tr><td class="fbody"><div align="center" class=ftitle>' + Div1 + '</div>' + Div2 + '</td></tr></table>'; document.body.innerHTML = '<center>' + css + body1 + '</center>'; window.print(); } }
知识改变命运,奋斗成就人生!- 已标记为答案 极度 2009年9月4日 9:02
全部回复
-
function DP() { if (window.print) { var Div1 = document.all.Div1.innerHTML; var Div2 = document.all.Div2.innerHTML; var css = '<style type="text/css" media=all> p { line-height: 120%} .ftitle { line-height: 120%; .font-size: 18px; color: #000000} td{ font-size: 10px; color: #000000}</style>'; var body1 = '<table width="640" border="0" cellspacing="0" cellpadding="5"><tr><td class="fbody"><div align="center" class=ftitle>' + Div1 + '</div>' + Div2 + '</td></tr></table>'; document.body.innerHTML = '<center>' + css + body1 + '</center>'; window.print(); } }
知识改变命运,奋斗成就人生!- 已标记为答案 极度 2009年9月4日 9:02