複製代碼代碼如下:
function preview(oper) {
if (oper < 10) {
bdhtml = window.document.body.innerHTML;//獲取當前頁的html代碼
sprnstr = "<!--startprint" + oper + "-->";//設置打印開始區域
eprnstr = "<!--endprint" + oper + "-->";//設置打印結束區域
prnhtml = bdhtml.substring(bdhtml.indexOf(sprnstr) + 18); //從開始代碼向後取html
prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));//從結束代碼向前取html
window.document.body.innerHTML = prnhtml;
window.print();
window.document.body.innerHTML = bdhtml;
} else {
window.print();
}
}
#outer {
display:table;
height:400px;
#position:relative;
overflow:hidden;
}
#middle {
display:table-cell;
vertical-align:middle;
#position:absolute;
#top:50%;
}
#inner {
#position:relative;
#top:-50%;
}
<div id=”outer”>
<div id=”middle”>
<div id=”inner”>
<!這裡是要垂直居中的內容>
</div>
</div>
</div>