jsp中如何实现打印功能
1个回答
展开全部
// JavaScript Document
function printArea
{(function($) {
var printAreaCount = 0;
$.fn.printArea = function()
{
var ele = $(this);
var idPrefix = "printArea_";
//removePrintArea( idPrefix + printAreaCount );
printAreaCount++;
var iframeId = idPrefix + printAreaCount;
var iframeStyle = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';
iframe = document.createElement('IFRAME');
$(iframe).attr({ style : iframeStyle,
id : iframeId
});
document.body.appendChild(iframe);
var doc = iframe.contentWindow.document;
doc.open();
$(document).find("link")
.filter(function(){
return $(this).attr("rel").toLowerCase() == "stylesheet";
})
.each(function(){
doc.write('<link type="text/css" rel="stylesheet" href="' +
$(this).attr("href") + '" >');
});
doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
doc.close();
var frameWindow = iframe.contentWindow;
frameWindow.close();
frameWindow.focus();
frameWindow.print();
};
//var removePrintArea = function(id)
//{
//$( "iframe#" + id ).remove();
//};
})(jQuery);
(function($) {
var printAreaCount = 0;
$.fn.printAreaTwice = function()
{
var ele = $(this);
var idPrefix = "printArea_";
//removePrintArea( idPrefix + printAreaCount );
printAreaCount++;
var iframeId = idPrefix + printAreaCount;
var iframeStyle = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';
iframe = document.createElement('IFRAME');
$(iframe).attr({ style : iframeStyle,
id : iframeId
});
document.body.appendChild(iframe);
var doc = iframe.contentWindow.document;
$(document).find("link")
.filter(function(){
return $(this).attr("rel").toLowerCase() == "stylesheet";
})
.each(function(){
doc.write('<link type="text/css" rel="stylesheet" href="' +
$(this).attr("href") + '" >');
});
doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div></br></br>');
doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
doc.close();
var frameWindow = iframe.contentWindow;
frameWindow.close();
frameWindow.focus();
frameWindow.print();
};
//var removePrintArea = function(id)
//{
//$( "iframe#" + id ).remove();
//};
})(jQuery);
}
<input type="button" onclick="$('#ceshi').printArea()">
<div id="ceshi">
<table><tr><td>12234</td></tr></table>
</div>
function printArea
{(function($) {
var printAreaCount = 0;
$.fn.printArea = function()
{
var ele = $(this);
var idPrefix = "printArea_";
//removePrintArea( idPrefix + printAreaCount );
printAreaCount++;
var iframeId = idPrefix + printAreaCount;
var iframeStyle = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';
iframe = document.createElement('IFRAME');
$(iframe).attr({ style : iframeStyle,
id : iframeId
});
document.body.appendChild(iframe);
var doc = iframe.contentWindow.document;
doc.open();
$(document).find("link")
.filter(function(){
return $(this).attr("rel").toLowerCase() == "stylesheet";
})
.each(function(){
doc.write('<link type="text/css" rel="stylesheet" href="' +
$(this).attr("href") + '" >');
});
doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
doc.close();
var frameWindow = iframe.contentWindow;
frameWindow.close();
frameWindow.focus();
frameWindow.print();
};
//var removePrintArea = function(id)
//{
//$( "iframe#" + id ).remove();
//};
})(jQuery);
(function($) {
var printAreaCount = 0;
$.fn.printAreaTwice = function()
{
var ele = $(this);
var idPrefix = "printArea_";
//removePrintArea( idPrefix + printAreaCount );
printAreaCount++;
var iframeId = idPrefix + printAreaCount;
var iframeStyle = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';
iframe = document.createElement('IFRAME');
$(iframe).attr({ style : iframeStyle,
id : iframeId
});
document.body.appendChild(iframe);
var doc = iframe.contentWindow.document;
$(document).find("link")
.filter(function(){
return $(this).attr("rel").toLowerCase() == "stylesheet";
})
.each(function(){
doc.write('<link type="text/css" rel="stylesheet" href="' +
$(this).attr("href") + '" >');
});
doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div></br></br>');
doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
doc.close();
var frameWindow = iframe.contentWindow;
frameWindow.close();
frameWindow.focus();
frameWindow.print();
};
//var removePrintArea = function(id)
//{
//$( "iframe#" + id ).remove();
//};
})(jQuery);
}
<input type="button" onclick="$('#ceshi').printArea()">
<div id="ceshi">
<table><tr><td>12234</td></tr></table>
</div>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |