點擊按鈕時選擇性地列印HTML 內容
Web 開發人員經常遇到需要允許使用者列印網頁的特定部分而不包括整個頁面內容。在這種情況下,問題就出現了:
如何在單擊按鈕時僅列印選定的 HTML 內容,而不包括頁面的其餘部分?
解決方案:
將隱藏的 HTML 內容保留在顯示中的建議解決方案: print div 是一種有效的方法。然而,有一個更簡單、更有效的方法:
建立列印樣式表:
- 建立一個名為「print.css」的CSS 文件,其中包含以下內容代碼:
<code class="css">@media print { .noPrint { display: none; } }</code>
此程式碼將在列印頁面時隱藏類別為「noPrint」的元素。
- 應用NoPrint 類別:
辨識不應該列印的HTML 內容,並為這些元素添加類別“noPrint”,例如:
<code class="html"><h1 id="No-Print">No Print</h1></code>
- 包含列印樣式表:
將以下行加入
中HTML 文件的部分:<code class="html"><link rel="stylesheet" href="print.css" media="print"></code>
- 新增列印按鈕:
建立一個點擊時觸發列印對話框的按鈕:
<code class="html"><button onclick="window.print()">Print</button></code>
說明:
點選列印按鈕時,將呼叫window.print() 方法,開啟瀏覽器的列印對話方塊。 CSS 媒體查詢 @media print { ... } 被觸發,導致類別「noPrint」的元素被隱藏。結果,僅列印所需的 HTML 內容。
以上是如何在按一下按鈕時僅列印選定的 HTML 內容?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

是的,youshouldlearnbothflexboxandgrid.1)flexboxisidealforone-demensional,flexiblelayoutslikenavigationmenus.2)gridexcelstcelsintwo-dimensional,confffferDesignssignssuchasmagagazineLayouts.3)blosebothenHancesSunHanceSlineHancesLayOutflexibilitibilitibilitibilitibilityAnderibilitibilityAndresponScormentilial anderingStruction

重構自己的代碼看起來是什麼樣的?約翰·瑞亞(John Rhea)挑選了他寫的一個舊的CSS動畫,並介紹了優化它的思維過程。

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframesispopularduetoitsversatoryand and powerincreatingsmoothcsssanimations.keytricksinclude:1)definingsmoothtransitionsbetnestates,2)使用AnimatingMultatingMultationMultationProperPertiessimultane,3)使用使用4)使用BombingeNtibalibility,4)使用CombanningWiThjavoFofofofoftofofo

CSSCOUNTERSAREDOMANAGEAUTOMANAMBERINGINWEBDESIGNS.1)他們可以使用forterablesofcontents,ListItems,and customnumbering.2)AdvancedsincludenestednumberingSystems.3)挑戰挑戰InclassINCludeBrowsEccerCerceribaliblesibility andperformiballibility andperformissises.4)創造性

使用滾動陰影,尤其是對於移動設備,是克里斯以前涵蓋的一個微妙的UX。傑夫(Geoff)涵蓋了一種使用動畫限制屬性的新方法。這是另一種方式。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

Atom編輯器mac版下載
最受歡迎的的開源編輯器

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)