jQuery Print函数用css打印div内容

标签 jquery css html printing

我为我的 Wordpress 插件提供了这个功能,它使用 jQuery 打印来自类“table_disp”的 div 的内容。我怎样才能打印 css 样式。

function pop_print(){
    w=window.open(null, 'Print_Page', 'scrollbars=yes');        
    w.document.write(jQuery('.table_disp').html());
    w.document.close();
    w.print();
}

有什么想法吗?

最佳答案

您需要在弹出窗口中包含您在父页面中使用的 SAME 样式表。您可能想要制作一个包含您的样式表的虚拟页面 stub /包装器,然后注入(inject)您的 HTML。

var myStyle = '<link rel="stylesheet" href="http://mysite.com/mystyle.css" />';
w.document.write(myStyle + jQuery('.table_disp').html());

关于jQuery Print函数用css打印div内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17753420/

相关文章:

jquery - 用另一种样式的 css 改变 jQ ui-accordion-content

javascript - 在表格行重新排序中显示向上/向下按钮

php - 在不使用 HTML 表单的情况下将 POST 数据发送到 PHP?

javascript - 如何使用 Robot Framework 删除字符串中的空格?

javascript - Rails 页面 JS 在真实浏览器/手动测试中有效,但在 PhantomJS 和 Selenium 规范中无效

css - 调整背景(图像)的大小而不裁剪它

javascript - 将 javascript 编写为 document.getElementById 函数的innerHTML

html - 为什么 'flex-grow' 在 Chrome 和 Firefox/Edge 中的行为不同?

javascript - 将预加载 img 转换为 iframe

html - Bootstrap 4 - 右对齐导航栏元素