[英]Rendering only included when devtools is open?
我正在嘗試制作“單擊此處以打印頁面”
<script type="text/javascript">
function PrintElem ()
{
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head>');
mywindow.document.write(document.head.innerHTML)
mywindow.document.write('</head><body >');
mywindow.document.write(document.body.children[1].innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();
}
</script>
<a onClick="printElem()" href="#"> print a div! </a>
所有樣式都包含在Head中,但是由於某些原因,當我單擊“ print a div!
” print a div!
時,會跳過這些樣式print a div!
鏈接,但是當我在打開DevTools的情況下單擊它時,是否包含該鏈接?
為什么?
你離這里太近了 您的函數PrintElem()
不應大寫,因為您使用適當的駝峰式printElem()
對其進行了調用
更正大寫問題時,效果很好。 無需其他更改。
<script type="text/javascript">
function printElem ()
{
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head>');
mywindow.document.write(document.head.innerHTML)
mywindow.document.write('</head><body >');
mywindow.document.write(document.body.children[1].innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();
}
</script>
<a onClick="printElem()" href="#"> print a div! </a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.