jquery - 如何打印保持CSS的div内容

标签 jquery css html printing

我想打印 div 内容,同时保持 css 应用于 div 及其内部 html。

我正在使用 jQuery Print Element 但它剥离了 css。

最佳答案

怎么样

function printDiv(id) {

  var html = "";

  $('link').each(function() { // find all <link tags that have
    if ($(this).attr('rel').indexOf('stylesheet') !=-1) { // rel="stylesheet"
      html += '<link rel="stylesheet" href="'+$(this).attr("href")+'" />';
    }
  });
  html += '<body onload="window.focus(); window.print()">+$("#"+id).html()+'</body>';
  var w = window.open("","print");
  if (w) { w.document.write(html); w.document.close() }

}

关于jquery - 如何打印保持CSS的div内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14093262/

相关文章:

javascript - 在表单对象上触发标准 "change"事件 - 由其上的任何监听器接收

jquery - Bootstrap 背景覆盖将图像设置在 "container-fluid"内,以便高度填充页面

jquery - 从特定标签中删除样式属性

javascript - 输入字段的jquery设置值

jquery - 将 ajax http post 转换为 python

javascript - 在样式表中快速切换 rems 和像素

css - SCSS/SASS 在文件之间共享变量、mixin 和样式而不导入

javascript - jQuery 只能在 .html 文件中工作,而不能在 .PHP 文件中工作?

php - 从 instagram 小部件调整显示图像的大小

html - 向下移动页面