-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[js] 第137天 用js实现页面局部打印和预览原理是什么呢?同时在IE上有什么不同? #1134
Labels
js
JavaScript
Comments
#print {
display: none !important;
}
@media print {
body > * {
display: none;
}
#print {
display: block!important;
}
} 以React为例封装一个PrintContainer import ReactDOM from 'react-dom'
const div = document.createElement('div')
div.id = 'print'
document.body.appendChild(div)
export default function PrintContainer (props) {
return ReactDOM.createPortal(props.children, div)
} |
@media print {
*:not(.somedom) {
display: none;
}
} 这样吗 |
这样写的话.somedom的子元素也不见了吧?😰 |
是哦 是我草率了:grin: |
<h1>这块内容不需要打印1</h1>
<!--startprint-->
<div class="content">
这里是需要打印的内容
.....
</div>
<!--endprint-->
<h1>这块内容不需要打印2</h1>
<button onclick="doPrint()">打印按钮</button> function doPrint() {
bdhtml = window.document.body.innerHTML;
sprnstr = "<!--startprint-->";
eprnstr = "<!--endprint-->";
prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
window.document.body.innerHTML = prnhtml;
window.print();
} |
bdhtml=window.document.body.innerHTML; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
第137天 用js实现页面局部打印和预览原理是什么呢?同时在IE上有什么不同?
The text was updated successfully, but these errors were encountered: