javascript - 仅打印网页的一部分

标签 javascript html css

我写了一段代码,它只打印网页的一部分。为此,我使用了 <div> .

代码如下:

<div id="printme">
    <table width='1000'  align="center">
    <tr><td>
    <h1> CANDIDATE DETAILS</h1>
             -----
             -----
             -----
             -----
</div>
<div id="dnt_print">
    <fieldset>
    <legend> <b>Uploads: </b></legend>
    <table width='900' align="center" >
              ----
              ----
              ----
     <td align="center">
       <input type="button" value="PRINT DETAILS" onclick="printdetails()">
     </td>
 </div>

我要打印的 JS 如下:

function printdetails()
{
    alert("Allow Pop-ups");
    var myWindow=window.open('','','width=200,height=100');
    var x=document.getElementById("printme").innerHTML;
    myWindow.document.write(x);
    myWindow.print();
    myWindow.close();
}

但问题是,当我点击打印时,弹出的新窗口显示了完整的详细信息,而不仅仅是 <div id="printme">--</div>。的 innerHTML !!请帮助我

最佳答案

与其让它变得复杂,不如通过使用值 hidden/visible 来使用元素的 visibility CSS 属性

关于javascript - 仅打印网页的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18430256/

相关文章:

html - 如何修复 Bootstrap 部分在 sm 屏幕上一起运行?

javascript - 错误类型错误 : Cannot read property 'value' of undefined in Angular 8

javascript - HTML页面滚动问题

javascript - 如何给每个圆圈一个随机的颜色?

html - IE9 是否支持 3D CSS 转换?

javascript - 删除 :before or :after CSS element and it's property with Jquery

javascript - 如何在页面刷新时保留 Bootstrap 向导步骤

javascript - 使用 JS Cookie 在 x 页面 View 后显示模态?

javascript - 将 glDatePicker 渲染为动态更改的日期

javascript - 移动滚动时延迟元素位置更新