如何在使用JavaScript打印时同时使用2个CSS
我需要打印一个表id,其中使用引导CSS作为表边框等,并为自定义表制作一个样式标记,以便在特定单元格上没有边框 我的问题是,如何同时使用2个CSS文件,使我的自定义CSS也能工作,因为在我的情况下,同时添加2个CSS文件似乎不起作用如何在使用JavaScript打印时同时使用2个CSS,javascript,css,Javascript,Css,我需要打印一个表id,其中使用引导CSS作为表边框等,并为自定义表制作一个样式标记,以便在特定单元格上没有边框 我的问题是,如何同时使用2个CSS文件,使我的自定义CSS也能工作,因为在我的情况下,同时添加2个CSS文件似乎不起作用 <script> function printData(){ var divToPrint=document.getElementById("example2"); newWin= window.open("", "width=480,
<script>
function printData(){
var divToPrint=document.getElementById("example2");
newWin= window.open("", "width=480, height=720");
newWin.document.write('<html><head>');
newWin.document.write('<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" type="text/css" />');
newWin.document.write('<link rel="stylesheet" href="custom.css" type="text/css" />');
newWin.document.write('</head><body>');
newWin.document.write(divToPrint.outerHTML);
newWin.document.write('</body></html>');
newWin.document.close();
setTimeout(function(){ newWin.print(); newWin.close(); },500);
return true;
}
$('#pronts').on('click',function(){
printData();
})
</script>
我希望我的表格在打印时在特定单元格上显示无边框,您需要的是使用
<link rel="stylesheet" href="print-style.css" type="text/css" media="print" />
注意媒体=印刷
这是一个用于控制样式的css文件的特殊标记,您根本不需要使用JavaScript。加载两个样式表,就像您正在做的一样,应该可以工作。如果你没有看到你想要的结果,这与你的CSS有关。你是否指向正确文件夹中的CSS?如果是这样,那么问题就出在你的CSS中。@Mikeluck是的。出于某种原因,当我创建新的css并将其放入css文件夹中,并在索引头中调用它时,它就可以工作了,而不是使用样式。当第一次只使用style,但决定使用custom.css清理空格或在css文件本身中使用@media print at规则时,使用media=print也可以。但是,“媒体”属性默认为“全部”,因此如果没有该属性,浏览器仍应选择样式。这样可以节省大量工作。决定将样式转换为css以清理空间