jquery如何利用jqprint插件实现局部打印和全局打印,下面web建站小编给大家详细介绍一下实现方法!
jqprint插件代码
(function($) {
var opt;
$.fn.jqprint = function (options) {
opt = $.extend({}, $.fn.jqprint.defaults, options);
var $element = (this instanceof jQuery) ? this : $(this);
if (opt.operaSupport && $.browser.opera)
{
var tab = window.open("","jqPrint-preview");
tab.document.open();
var doc = tab.document;
}
else
{
var $iframe = $("<iframe />");
if (!opt.debug) { $iframe.css({ position: "absolute", width: "0px", height: "0px", left: "-600px", top: "-600px" }); }
$iframe.appendTo("body");
var doc = $iframe[0].contentWindow.document;
}
if (opt.importCSS)
{
if ($("link[media=print]").length > 0)
{
$("link[media=print]").each( function() {
doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' media='print' />");
});
}
else
{
$("link").each( function() {
doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' />");
});
}
}
if (opt.printContainer) { doc.write($element.outer()); }
else { $element.each( function() { doc.write($(this).html()); }); }
doc.close();
(opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).focus();
setTimeout( function() { (opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).print(); if (tab) { tab.close(); } }, 1000);
}
$.fn.jqprint.defaults = {
debug: false,
importCSS: true,
printContainer: true,
operaSupport: true
};
jQuery.fn.outer = function() {
return $($('<div></div>').html(this.clone())).html();
}
})(jQuery);
调用方法:
function print(){
$("#div").jqprint(); //需要打印的div
}
阻止事件冒泡e.stopPropagation()不兼容ie6/7/8解决方法
阻止默认行为ev.preventDefault()不兼容ie6/7/8解决方法
classList.add和classList.remove不兼容ie6/7/8/9解决方法
自定义属性data-* 不兼容ie6/7/8/9/10解决方法
getElementsByclassName不兼容IE6/7/8解决方法!
上面是“jquery利用jqprint实现局部打印(兼容IE8)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_2569.html
workflows工作流
一个男孩在吃西瓜ComfyUI工作流
海中一头鲸鱼ComfyUI工作流
一架令人难忘的美丽钢琴ComfyUI工作流
树上一个快乐的猕猴桃ComfyUI工作流
一张超现实主义美女照片ComfyUI工作流
星空星域星球comfyui工作流
图生图工作流:一键转换成高清动漫照片
一只蚊子被嵌在琥珀中ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

自动打字效果(惊喜在后面)
利用css3做一个动态loading效果
3d文字360度旋转
css3搭积木叠加图形
如何利用svg做一个有趣的loading动画加载
js+css3做一个灯泡开灯关灯效果
用canvas实现画板涂鸦效果
canvas黑洞漩涡(canvas+js)






