我正在尝试使用 JavaScript 在我的文本周围打印椭圆形。它不工作。这是我的代码。下面我有一个 fiddle 的链接。
<link rel="stylesheet" href="styles.css" media="screen, print">
@media print {
.oval {
border-radius: 50%;
behavior: url(PIE.htc); /* remove if you don't care about IE8 */
width: 2%;
padding: 1px;
background: #fff;
border: 1px solid #666;
color: #666;
text-align: center;
}
}
<form id="myPrint">
<div class="oval">print this</div>
<input type="button" value="PRINT" onClick="printTbl()">
</form>
<script language="javascript" type="text/javascript">
function printTbl() {
var TableToPrint = document.getElementById('myPrint');
newWin = window.open("");
newWin.document.write(TableToPrint.outerHTML);
newWin.print();
newWin.close();
}
</script>
这是一个 fiddle :https://jsfiddle.net/jgvg43gm/4/ 甚至不在 fiddle 中打印。 有什么想法吗?
最佳答案
那是因为您在新窗口中编写了 html,该窗口没有引用您的 CSS,因此未应用样式。
(js fiddle 不起作用,因为您需要在头部而不是在 onLoad
函数中设置脚本,这是默认设置。请参见 JS 窗口的右上角)
关于javascript - 使用 JavaScript 打印 CSS 椭圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46507298/