【发布时间】:2021-02-01 01:08:57
【问题描述】:
这是我想要实现的示例,首先用户将选择图像,然后他们将输入他们想要在打印页面上显示的图像块数,我已经创建了添加图像并打印它的功能但它只是我想创建的一个,可以打印多个图像,这取决于用户输入的内容。
这是我的代码:
var myApp = new function() {
this.geltint = function() {
var tab = document.getElementById('geltint');
var style = "<style>";
style = style + "table {width: 100%;font: 17px Calibri;}";
style = style + "table, th, td {border: solid 1px #DDD; border-collapse: collapse;";
style = style + "padding: 2px 3px;text-align: center;}";
style = style + "</style>";
var win = window.open('', '', 'height=700,width=700');
win.document.write(style); // add the style.
win.document.write(tab.outerHTML);
win.document.close();
win.print();
}
}
var myApp2 = new function() {
this.powdery = function() {
var tab = document.getElementById('powdery');
var style = "<style>";
style = style + "table {width: 100%;font: 17px Calibri;}";
style = style + "table, th, td {border: solid 1px #DDD; border-collapse: collapse;";
style = style + "padding: 2px 3px;text-align: center;}";
style = style + "</style>";
var win = window.open('', '', 'height=700,width=700');
win.document.write(style); // add the style.
win.document.write(tab.outerHTML);
win.document.close();
win.print();
}
}
var myApp3 = new function() {
this.powdery5ml = function() {
var tab = document.getElementById('powdery5ml');
var style = "<style>";
style = style + "table {width: 100%;font: 17px Calibri;}";
style = style + "table, th, td {border: solid 1px #DDD; border-collapse: collapse;";
style = style + "padding: 2px 3px;text-align: center;}";
style = style + "</style>";
var win = window.open('', '', 'height=700,width=700');
win.document.write(style); // add the style.
win.document.write(tab.outerHTML);
win.document.close();
win.print();
}
}
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#geltint')
.attr('src', e.target.result)
.width(244.8)
.height(187.2);
};
reader.readAsDataURL(input.files[0]);
}
}
function readURL2(input) {
if (input.files && input.files[0]) {
var reader2 = new FileReader();
reader2.onload = function(e) {
$('#powdery')
.attr('src', e.target.result)
.width(172.8)
.height(230.4);
};
reader2.readAsDataURL(input.files[0]);
}
}
function readURL3(input) {
if (input.files && input.files[0]) {
var reader2 = new FileReader();
reader2.onload = function(e) {
$('#powdery5ml')
.attr('src', e.target.result)
.width(244.8)
.height(105.6);
};
reader2.readAsDataURL(input.files[0]);
}
}
这是我的 HTML 代码:
<HTML>
<head>
<link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js">
</script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article,
aside,
figure,
footer,
header,
group,
menu,
nav,
section {
display: block;
}
</style>
</head>
<body>
<div id="1stimage">
<input type='file' onchange="readURL(this);" />
<img id="geltint" src="#" alt="your image" />
<p>
<input type="button" value="Print Table" onclick="myApp.geltint()" />
</p>
</div>
<div id="2ndimage">
<input type='file' onchange="readURL2(this);" />
<img id="powdery" src="#" alt="your image" />
<p>
<input type="button" value="Print Table" onclick="myApp2.powdery()" />
</p>
</div>
<div id="3rdimage">
<input type='file' onchange="readURL3(this);" />
<img id="powdery5ml" src="#" alt="your image" />
<p>
<input type="button" value="Print Table" onclick="myApp3.powdery5ml()" />
</p>
</div>
</body>
</html>
这是示例,我希望我的输出看起来简单明了任何您可以与我分享的建议或想法,非常感谢。
用户将选择一个图像,然后输入他们想要多少份图像的数量,然后按打印它会显示这样的打印预览以及用户输入的图像总数
【问题讨论】:
标签: javascript html jquery printing