1
我正面临打印页面内容的问题。我用window.print()
,但它打印整个窗口。我只需要在我的页面上打印一些内容。请给我一个解决方案。在yii2中打印页面内容
代码:
<html>
<head>
<script>
function printContent(el)
{
var restorepage = document.body.innerHTML;
var printcontent = document.getElementById(el).innerHTML;
document.body.innerHTML = printcontent;
window.print();
document.body.innerHTML = restorepage;
}
</script>
</head>
<body>
<h1>My page</h1>
<div id="div1">DIV 1 content...</div>
<button onclick="printContent('div1')">Print Content</button>
</body>
</html>