Today's work encountered a problem: the use of textarea text field to hold a simple text message, do not need to have a picture, but each paragraph of text line and indentation is needed.
To achieve this, my idea is to use regular expressions to match the line breaks in all text information, and then replace them with HTML <p> tags, storing the replaced text information in the database when it is displayed, and displaying the data directly from the database.
Here is my implementation code:
Html:
<HTMLxmlns= "http://www.w3.org/1999/xhtml"><Headrunat= "Server"> <title></title> <styletype= "Text/css">. Articlep{font-size:16px;Color:#333;text-indent:32px;Line-height:28px;Margin-bottom:10px;} </style><Scriptsrc=".. /scripts/jquery-1.4.1.js "type= "Text/javascript"></Script> <Scripttype= "Text/javascript"> $(function () { $("#ceshi"). Click (function () { varValstr= "<p class=\ "Articlep\" >" + $("#txtNewsContent"). Val (). toString (). Replace (/(\ r) *\n/G,"</p><p class=\ "Articlep\" >"). Replace (/\s/G," ") + "</p>"; alert (VALSTR); $("#transferedtxt"). HTML (valstr.tostring (). Replace (/<p>/G,""). Replace (/<\/p>/G,"")); }); }) </Script></Head><Body> <formID= "Form1"> <Div> <label><spanstyle= "color:red;">*</span>News content:</label> <textareaID= "Txtnewscontent"rows= "Ten"cols= " the"> </textarea> </Div> <inputtype= "button"value= "Ceshi"ID= "Ceshi"/> <BR/> <DivID= "Transferedtxt"> </Div> </form></Body></HTML>
Input content:
Recently, the railway sector once again ushered in a unified system of pay increases, according to the different positions, each month to increase the salary range from 300 to 500 yuan.
This is the 4th time for the railway department to unify the pay increase after Sheng Guangzu's successor as Minister of Railways and general manager of China Railway Corporation.
Output content:
Regular expressions replace line breaks in text