JS 實現分頁列印

來源:互聯網
上載者:User

標籤:tab   htm   blog   ext   應該   分頁   after   asc   對象   

在調用window.print()時,可以實現列印效果,但內容太多時要進行分頁列印。

在樣式中有規定幾個列印的樣式

page-break-before和page-break-after CSS屬性並不會修改網頁在螢幕上的顯示,這兩個屬性是用來控制檔案的列印方式。

每個列印屬性都可以設定4種設定值:auto、always、left和right。其中Auto是預設值,只有在有需要時,才需設定分頁符號 (Page breaks)。

page-break-before若設定成always,則是在遇到特定的組件時,印表機會重新開始一個新的列印頁。

page-break-before若設定成left,則會插入分頁符號,直到指定的組件出現在一個左邊的空白頁上。

page-break-before若設定成right,則會插入分頁符號,直到指定的組件出現在一個右邊的空白頁上。

page-break-after屬性會將分頁符號加在指定組件後,而非之前。

在下列程式中您將可以看到這些屬性的設定,

 

<HTML>  <HEAD>    <TITLE>Listing 14-4</TITLE>  </HEAD>  <BODY>    <DIV>This is the first DIV.</DIV>    <DIV STYLE="page-break-before:always">This is the second DIV.</DIV>    <DIV STYLE="page-break-after:always">This is the third DIV.</DIV>    <DIV>This is the fourth DIV.</DIV>    <DIV STYLE="page-break-before:right">This is the fifth DIV.</DIV>    <DIV STYLE="page-break-after:right">This is the sixth DIV.</DIV>    <DIV>This is the last DIV.</DIV>  </BODY></HTML>
值 描述
auto 預設值。如果必要則在元素前插入分頁符
always 在元素前插入分頁符
avoid 避免在元素前插入分頁符
left 在元素之前足夠的分頁符,一直到一張空白的左頁為止
right 在元素之前足夠的分頁符,一直到一張空白的右頁為止
inherit 規定應該從父元素繼承 page-break-before 屬性的設定

 

在Dom對象中pageBreakBefore屬性

文法:

    Object.style.pageBreakBefore=auto|always|avoid|left|right

<html>  <head>    <script type="text/javascript">      function setPageBreak()      {        document.getElementById("p2").style.pageBreakBefore="always";      }    </script>  </head>  <body>    <p>This is a test paragraph.</p>    <input type="button" onclick="setPageBreak()" value="Set page-break" />    <p id="p2">This is also a test paragraph.</p>  </body></html>

 

 

 

 

 

JS 實現分頁列印

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.