【问题标题】:Add white breaking line after text in textarea在 textarea 中的文本后添加白色换行符
【发布时间】:2018-11-05 21:11:30
【问题描述】:

我希望在文本区域中的文本之后有一个断行或两个断行,而不需要用户按“Enter”来换行,这样空行就会显示在打印页面中

<html >
<head>

<!-- script print button -->
 <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 dir="rtl">');
        childWindow.document.write(document.getElementById('targetTextArea').value.replace(/\n/gi,'<br/>'));
        childWindow.document.write('</body></html>');
        childWindow.print();
        childWindow.document.close();
        childWindow.close();
      }
    </script>
<style type="text/css">

textarea {
direction: rtl; 
 background-color: white;
 font-size: 1em;
 font-weight: bold;
 font-family: Verdana, Arial, Helvetica, sans-serif;
 border: 1px solid #00acee;
 resize: none;
}

</style>
</head>

<body>
  <p>
    <TEXTAREA name="thetext" rows="20" cols="80"id="targetTextArea" placeholder="قم بنسخ و لصق الطلب لملأه و التعديل عليه و طباعته بالزر أسفله ......">
</TEXTAREA>
   </p>
   <!-- print button -->
  <center> <input type="button" onclick="printTextArea()" value="طباعة"/></center>
</body>
</html>

【问题讨论】:

    标签: javascript html css printing textarea


    【解决方案1】:

    这应该可以解决问题。如果填充看起来不好,请尝试添加边距。

    @media print {
       textarea {padding-bottom:2cm;}
    }
    

    【讨论】:

    • close answer without "@media print" just css textarea {padding-bottom:2cm;} 即使textarea被扩展的问题,你将在textarea的底部有2cm的空白区域2厘米
    猜你喜欢
    • 2019-10-13
    • 2016-09-23
    • 2013-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-01
    相关资源
    最近更新 更多