如何使用 JavaScript 设置元素后的分页行为?

javascriptobject oriented programmingfront end technology

使用 JavaScript 中的 pageBreakAfter属性设置元素后的分页行为。使用 always 属性设置元素后的分页行为。

注意 − 更改将在打印或查看打印预览时可见。

示例

您可以尝试运行以下代码以使用 JavaScript 返回元素后的分页行为 −

<!DOCTYPE html>
<html>
   <body>
      <h1>Heading 1</h1>

      <p>This is demo text.</p>
      <p>This is demo text.</p>
      <p id = "myFooter">This if footer text.</p>

      <button type = "button" onclick="display()">Set page-break</button>

      <script>
         function display() {
            document.getElementById("myFooter").style.pageBreakAfter = "always";
         }
      </script>
   </body>
</html>

相关文章