html 代碼:
【注意】:這里的注釋一定要寫,用來標記要打印 DOM 元素的起始節點。
如果想動態插入打印注釋的標識,需要如下 js 代碼:
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();