1. 程式人生 > >網頁頁面列印選擇的內容

網頁頁面列印選擇的內容

Js指令碼如下:  

  function preview() {

            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();

        }

<!--startprint-->:開始位置標籤,放置在要列印內容開始的位置

<!--endprint-->:結束位置標籤,放置在列印內容結束的位置