我想通过在Web表单中输入文件名来打印图像文件。
我发现以下代码可以在按下按钮时打印文件“ 1ABC。jpg”。 但是,我想创建2个表单,可以在第一个表单中输入“ 1”,然后在下一个表单中输入“ ABC”,然后按Enter键打印“ 1ABC.jpg”,该文件位于同一文件夹中。
基本上有两种输入形式,它们会被追加,然后传递给VoucherSourcetoPrint函数。
<!DOCTYPE html>
<html>
<title>PRINT VOUCHER</title>
<head>
<script type="text/javascript">
function VoucherSourcetoPrint(source) {
return "<html><head><script>function step1(){\n" +
"setTimeout('step2()', 10);}\n" +
"function step2(){window.print();window.close()}\n" +
"</scri" + "pt></head><body onload='step1()'>\n" +
"<img src='" + source + "' /></body></html>";
}
function VoucherPrint(source) {
Pagelink = "about:blank";
var pwa = window.open(Pagelink, "_new");
pwa.document.open();
pwa.document.write(VoucherSourcetoPrint(source));
pwa.document.close();
}
</script>
<style type="text/css">
.myButton {
background-color: #77b55a;
border: 1px solid #4b8f29;
display: inline-block;
cursor: pointer;
color: #f0ebf0;
font-family: arial;
font-size: 13px;
font-weight: bold;
margin: 5px;
padding: 7px 35px;
text-decoration: none;
}
</style>
</head>
<body>
<div style="width: 400px; float: left;">
<center>
<span style="color: Blue; font-size: 30px;">Voucher 1</span>
</center>
<br />
<img src="1ABC.jpg" style="width: 400px; height: 200px;" alt="Voucher 1" />
<center>
<a href="#" onclick="VoucherPrint('1ABC.jpg'); return false;" class="myButton">
Print Voucher
</a>
</center>
</div>
</body>
</html>
对以上代码的编辑将不胜感激! :D