如何在angularjs中进行打印时隐藏文本框

时间:2018-05-23 06:22:06

标签: javascript html css angularjs

虽然pring文本框也会出现在打印页面中,但它看起来很糟糕。如何删除该文本框并仅显示输入的文本值。

Image

请找到图片。我该如何解决这个问题。我只想显示我在文本框中输入的文本。请帮助我如何解决这个问题。

jsfiddle



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function PrintDiv() {
            var contents = document.getElementById("dvContents").innerHTML;
            var frame1 = document.createElement('iframe');
            frame1.name = "frame1";
            frame1.style.position = "absolute";
            frame1.style.top = "-1000000px";
            document.body.appendChild(frame1);
            var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument;
            frameDoc.document.open();
            frameDoc.document.write('<html><head><title>DIV Contents</title>');
            frameDoc.document.write('</head><body>');
            frameDoc.document.write(contents);
            frameDoc.document.write('</body></html>');
            frameDoc.document.close();
            setTimeout(function () {
                window.frames["frame1"].focus();
                window.frames["frame1"].print();
                document.body.removeChild(frame1);
            }, 500);
            return false;
        }
    </script>
</head>
<body>
    <form id="form1">
    <span style="font-size: 10pt; font-weight: bold; font-family: Arial">ASPSnippets.com
        Sample page</span>
    <hr />
    <div id="dvContents" style="border: 1px dotted black; padding: 5px; width: 300px">
        <span style="font-size: 10pt; font-weight: bold; font-family: Arial">Hello,
            <br />
            This is <span style="color: #18B5F0">Mudassar Khan</span>.<br />
            Hoping that you are enjoying my articles!</span>
            <input type="text" class="input printText" value="test">
    </div>
    <br />
    <input type="button" onclick="PrintDiv();" value="Print" />
    </form>
</body>
</html>
&#13;
&#13;
&#13;

Image

2 个答案:

答案 0 :(得分:1)

请为想要的输入.printText添加一些课程:

<td width="267">Policy <br/>Number:  <input type="text" class="input printText" size="30"></td>
css中的

会隐藏输入的边框

@media print
{
    #non-printable { display: none!important; }
    #printable { display: block; }
    .printText{border:none!important;}
}

答案 1 :(得分:0)

input添加自定义类,让我们说print-hidden并使用css对此@media进行应用

@media print {
  .print-hidden {
    display: none;
  }
}