如何使用JavaScript在元素内设置分页符行为?

使用JavaScript中的pageBreakInside 属性设置元素内的分页行为。使用auto 属性在元素内插入分页符。如果需要,可以使用auto prevent 属性值自动在元素内插入分页符,或者分别避免分页符。

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

示例

您可以尝试运行以下代码以使用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.pageBreakInside = "auto";
         }
      </script>
   </body>
</html>
猜你喜欢