Can't get exact print out result from HTML textarea

问题: I am creating a form for medical prescription. Here one of the textarea field name is new prescription. Doctor will insert value here like 1. medicine-l 1+1+1 2. medi...

问题:

I am creating a form for medical prescription. Here one of the textarea field name is new prescription. Doctor will insert value here like

1. medicine-l
   1+1+1
2. medicine-2
   1+0+1

But while I print out the prescription this new prescription field shows it's value like

1.medicine-1 1+1+1 2.medicine-2 1+0+1

But I want to printout the value of new prescription just like how doctor inserted.

How can I do it? Anybody Help Please ?


回答1:

The line breaks are actually preserved untill you print the text out. HTML doesn't doesn't detect the line breaks in the text.

Try this for JS:

textAreaText.replace(/(?:rn|r|n)/g, '<br>');

How do I replace all line breaks in a string with <br /> tags?

Try this for PHP : http://php.net/manual/en/function.nl2br.php


回答2:

You should be able to do this using the CSS property white-space.

Example:

.textarea-class {
  white-space: pre-wrap;
}

Consult the MDN docs for a very nice overview if the various options, but it seems like you want either pre (just as it is), pre-wrap (maintains spacing and line breaks, but wraps), or even pre-line (maintains line breaks but not spacing, and wraps).

You’ll want to put this in your print stylesheet.

  • 发表于 2019-02-19 23:09
  • 阅读 ( 180 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除