如何使用JavaScript设置元素后的分页符行为?
使用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>