打印页面时不显示动态创建的元素 [英] Dynamically created element not appearing when page is printed

查看:77
本文介绍了打印页面时不显示动态创建的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery动态创建了一些元素:

I've some dynamically created elements with jQuery:

<body>
<a href="#" id="trigger">test</a>
    <a href="javascript:window.print()">print</a>
</body>

jQuery:

$(document).ready(function() {
    $('#trigger').click(function(e) {
        $('body').append('<div id="test"></div>');
    });
});

CSS:

#test { 
    position: absolute; 
    left: 50px; 
    top: 100px; 
    width: 500px; 
    height: 25px; 
    background-color: #F00; 
}

如您所见,我已经创建了一个print按钮,并希望打印出该#test元素.不幸的是,工作表只有两个按钮.看来您无法打印出动态元素.

As you can see I've created a print button and would like to print out that #test element. Unfortunately the sheet only has the two buttons. It seems that you can't print out dynamic elements.

非常感谢您的帮助.

推荐答案

打印网页时,浏览器会自动忽略背景色(因为您通常不希望用整个彩色墨盒来打印网页背景).您生成的div是空的,并且在页面上可见的唯一方法是因为其背景颜色不同.

When you print a web page, the browser automatically ignores background color (because you usually don't want to spend your entire color cartridge to print a web page background). Your generated div is empty and the only way it is visible on the page is because of its different background color.

如果您将内容添加到div或边框,它也应该在打印输出中可见.

If you add content to the div or e.g. a border it should be visible in the printout as well.

这篇关于打印页面时不显示动态创建的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆