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工作流
爱因斯坦在做实验3d动漫ComfyUI工作流
一只蚂蚁在花丛中找食物ComfyUI工作流
乡村枯树黄花comfyui工作流
雪地里一只可爱的小老虎
一群蚂蚁在路上忙碌着ComfyUI工作流
树上挂着一只表情可爱的香蕉ComfyUI工作流二
一支令人难忘的狙击步枪ComfyUI工作流
一条赤壁龙从蛋中孵化出来ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

3D立体人物效果
Bootstrap可视化拖放布局
利用css绘画棋盘布局(象棋)
3d文字动画效果
css3+js菜单点击动态效果
利用js+css3做一个小鱼游泳特效
css3结合svg做一个动态广告










