【问题标题】:How to print text from textarea?如何从 textarea 打印文本?
【发布时间】:2011-01-19 07:33:50
【问题描述】:

我想从文本区域打印文本。

我有一个文本区域,用户可以更新其中的文本。当用户从 textarea 更新文本然后打印更新的文本时,可以在页面上打印。并且此文本可以在没有文本区域的打印页面上打印。

请提出任何解决方案。

谢谢

【问题讨论】:

    标签: javascript ruby-on-rails printing


    【解决方案1】:

    我想我得到了你想要的。试试看:

    <html>
      <head>
        <title>Print TextArea</title>
        <script type="text/javascript">
          function printTextArea() {
            childWindow = window.open('','childWindow','location=yes, menubar=yes, toolbar=yes');
            childWindow.document.open();
            childWindow.document.write('<html><head></head><body>');
            childWindow.document.write(document.getElementById('targetTextArea').value.replace(/\n/gi,'<br>'));
            childWindow.document.write('</body></html>');
            childWindow.print();
            childWindow.document.close();
            childWindow.close();
          }
        </script>
      </head>
      <body>
        <textarea rows="20" cols="50" id="targetTextArea">
          TextArea value...
        </textarea>
        <input type="button" onclick="printTextArea()" value="Print Text"/>
      </body>
    </html>
    

    基本上,这将打开另一个子窗口并在其上执行 javascript print,这样 textarea 和其他内容就不会被打印出来。

    【讨论】:

    • 顺便说一句,在您的问题中添加了另一个标签“javascript”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    • 2018-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多