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工作流
3d卡通风格多彩头发的女人
一只乌鸦栖息在一盏神灯上
一朵由琥珀制成的孤独美丽的玫瑰
外星人ComfyUI工作流
一架受损严重的宇宙飞船内有一只猫
一只黑色章鱼ComfyUI工作流
一辆在泥潭中奔跑的布加迪ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

css3做一个风雨雷电天气动态图标
jquery鼠标滑过图片边框特效(jquery.focus-follow插件)
canvas空间文本射线
纯css制作卡通头像(随鼠标转头)
数字滚动效果(兼容IE6/IE8)
黑客入侵效果代码
用canvas实现画板涂鸦效果
3d文字动画效果











