HTML onbeforeprint 事件屬性
HTML onbeforeprint 事件屬性會在列印頁面或 HTML 文件中顯示列印對話方塊之前觸發。
語法
語法如下:
<tagname onbeforeprint=”script”></tagname>
讓我們來看一個 HTML onbeforeprint 事件屬性的示例:
示例
<!DOCTYPE html> <html> <head> <style> body { color: #000; height: 100vh; background-color: #FBAB7E; background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%); text-align: center; padding: 20px; } p { font-size: 1.1rem; } </style> </head> <body onbeforeprint="get()"> <h1>HTML onbeforeprint Event Attribute Demo</h1> <p>I'm a paragraph HTML element with some dummy text.</p> <p style="color:#db133a;">Now try to print this document.</p> <div class="show"></div> <script> function get() { document.body.style.background = "lightblue"; } </script> </body> </html>
輸出
現在嘗試使用 Ctrl + P 列印文件,並觀察 onbeforeprint 事件屬性如何發揮作用。
廣告