如何实现打印功能 求具体代码
大概打印出来是这种 我点击哪个数据就要打印哪个数据 这种该怎么写 不会控制这个打印机 大家有没有相关的代码可以参考一下 谢谢啊 java 打印 web 代码
[解决办法]
<script type="text/javascript" src="/mshopsuhf/js/common.js"> </script>
<script type="text/javascript" src="/mshopsuhf/js/checkform.js"> </script>
<link href="/mshopsuhf/css/main.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
<!--
function BusyWaitMsg(msg,w,h)
{
if (!msg) msg="正在执行中,请稍候...";
if (!w)w=document.body.offsetWidth;
if (!h)h=Math.round(screen.height-180);
//var l=(document.body.offsetWidth-w)/2;
//var t=(document.body.offsetHeight-h)/2;
var l=10;
var t=10;
document.all.BusyDiv_F.style.display="";
window.frames.BusyFrame_F.document.all["MsgText"].innerHTML=msg;
document.all.BusyFrame_F.style.width=w;
document.all.BusyFrame_F.style.height=h;
document.all.BusyFrame_F.style.left=l;
document.all.BusyFrame_F.style.top=t;
document.all.BusyFrame_F.style.right=10;
document.all.BusyFrame_F.style.display="";
}
//打印忙提示的HTML
document.writeln ('<Div id="BusyDiv_F" style="position:absolute; top:0; left:0; width:100%; height:100%; z-index:1010;display:none;border:0px"><table style="width:100%;height:100%;background-color: transparent;"><tr><td></td></tr></table></Div>');
document.writeln ('<iframe allowTransparency="true" id="BusyFrame_F" scrolling="no" frameborder=0 style="border:0px solid #4284F7;position: absolute;z-index:1020; filter :\'progid:DXImageTransform.Microsoft.Shadow(direction=135,color=#AAAAAA,strength=5)\';display: none"></iframe>');
window.frames.BusyFrame_F.document.write('<HTML><BODY onselectstart="return false;" leftmargin=0 topmargin=0 rightmargin=0 bottommargin=0 bgcolor="#F7F7F7" style="background-color=transparent"><table align=center style="height:100%;width:100%;border:1px solid #4284F7" ><tr><td><table style="height:100%;width:100%;font-size:9pt; border:0px solid #4284F7" ><tr><td width="20"><img src="/mshopsuhf/images/loading.gif"></td><td><font id=MsgText></font></td></tr></table></td></tr></table></BODY></HTML>');
window.frames.BusyFrame_F.document.close();
//-->
</script>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/javascript" src="/mshopsuhf/js/dialog.js" ></script>
<script type="text/javascript" src="/mshopsuhf/headshop/js/jquery-1.3.2.min.js" ></script>
<script type="text/javascript" src="/mshopsuhf/headshop/js/jquery-barcode.0.2.js" ></script>
<script type="text/javascript" src="/mshopsuhf/headshop/js/jquery-printArea.2.1.js" ></script>
<script type="text/javascript">
var HKEY_Root,HKEY_Path,HKEY_Key;
HKEY_Root="HKEY_CURRENT_USER";
HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\";
//设置网页打印的页眉页脚为空
function PageSetup_Null()
{
try {
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
} catch(e){}
}
//恢复网页打印的页眉页脚
function SetupPage()
{
try{
var RegWsh = new ActiveXObject("WScript.Shell");
hkey_key="header"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P")
hkey_key="footer"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&b&d") //去掉了&u 因为我不想显示当前打印页的网址
hkey_key="margin_bottom";
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"0.39"); //0.39相当于把页面设置里面的边距设置为10
hkey_key="margin_left";
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"0.39");
hkey_key="margin_right";
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"0.39");
hkey_key="margin_top";
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"0.39");
}
catch(e){
alert(e);
}
}
function printsetup(){
// 打印页面设置
wb.execwb(8,1);
}
function printpreview(){
// 打印页面预览
PageSetup_Null();
wb.execwb(7,1);
}
function printit()
{
if (confirm('确定打印吗?')) {
PageSetup_Null();
wb.execwb(6,6)
}
}
</script>
<style type="text/css" media="print">
.noprint{display : none; }
</style>
</HEAD>
<BODY>
<div class="PrintArea" align="center"><div id="bcTarget"><!-- <OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT> -->
<h3 style="padding-left:30px;">亿学软件</h3>
----------------------------------------------------<br/>
收银员:A 单号:1399<br/>
日期:2013-05-31<br />
----------------------------------------------------<br/>
<table style="font-size:12px;">
<tr>
<td>商品名称</td><td style="padding-left:10px;">数量</td><td style="padding-left:10px;">单价</td><td style="padding-left:10px;">总价</td>
</tr>
<tr>
<td>
多吉美抽取式面纸
</td>
<td style="padding-left:10px;">
1.0
</td>
<td style="padding-left:10px;">
20.0
</td>
<td style="padding-left:10px;">
20.0
</td>
</tr>
<tr>
<td>
多吉美抽取式面纸
</td>
<td style="padding-left:10px;">
1.0
</td>
<td style="padding-left:10px;">
20.0
</td>
<td style="padding-left:10px;">
20.0
</td>
</tr>
</table>
------------------------------<br />
合计:40.0<br />
谢谢您的惠顾,欢迎您再次光临!<br />
请保留小票 <br/></div></div>
<input type="button" id="print_button" style="cursor: pointer; height: 22px;" value="打 印"></input>
<script type="text/javascript">
//div: div#print_button
$("#print_button").click(function(){
$("div.PrintArea").printArea({mode: "popup", popClose: false,popHt:10,popWd:10,popX:0,popY:0});
});
</script>
</BODY>
</HTML>