我有一个示例html页面,我想打印这个页面只有三个副本,也改变原始(在右上角提到),只有当我们采取这个页面的第二个副本复制。我们有没有办法使用Javascript或Jquery来实现这一点呢?
function myFunction() {
window.print();
}
.original {
float : right;
margin-right : -0.1cm;
}
<p>Click the button to print the current page.</p>
<button onclick="myFunction()">Print this page</button>
<div class="col-xs-4"></div>
<div class="col-xs-1 original"><font color="red"><strong>Original</strong></font></div>
发布于 2017-08-11 08:04:21
我试着给出一个简单的解决方案,暂时保留打印计数的标志。请查看下面的内容。
var v1=0;
function myFunction() {
if (v1==0) {
window.print();
}
else {
window.print();
$('#s1').text('Duplicate');
}
v1++;
}
.original {
float : right;
margin-right : -0.1cm;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Click the button to print the current page.</p>
<button onclick="myFunction()">Print this page</button>
<div class="col-xs-4"></div>
<div class="col-xs-1 original"><font color="red"><strong id="s1" >Original</strong></font></div>
希望这能对你有所帮助!
发布于 2019-08-23 05:27:28
这里是示例代码。现在请查收。
#printable { display: none; }
@media print
{
#non-printable { display: none; }
#printable { display: block; }
}
</style>
</head>
<body>
<div id="non-printable">
Your normal page contents
</div>
<div id="printable">
Printer version <div id="count"></div>
</div>
<a href="#" id="autoclick" onclick="window.print();">Print<a>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
(function() {
var beforePrint = function() {
console.log('Functionality to run before printing.');
};
var afterPrint = function() {
console.log('Functionality to run after printing');
var vals = $('#inc').val();
var incval = parseInt(vals)+parseInt(1);
$('#inc').val(incval);
if(incval < 3)
{
window.setTimeout('window.print()',5000);
}
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
}());
</script>
<input type="text" id="inc" value="0">
https://stackoverflow.com/questions/45629602
复制相似问题