How to get a wrap and space in the Textarea tag

small to give us share with you how to obtain textarea tag line breaks, and spaces, I believe most people do not understand how, so share this article for your reference, I hope you finish reading this article after a great Harvest, let us let us know together!

HTML TEXTAREA Definitions and Usage: Tag defines multi-line text input controls.

The text area can accommodate unlimited number of texts, the default font of the text is a equivalent wide font (usually a Courier). 1. COLS, vertical columns. In the case where the style sheet is not made, it represents the number of bytes that can be accommodated in a row. For example, cols = 60, indicating that you can accommodate up to 60 bytes in a row, that is, 30 Chinese characters. Also note that the width of the text box is to adjust, enter the value of cols, and then define the size of the input text font (not defined, the default value will be used), then the width of the text box is determined.

2. ROWS, horizontal column. Indicates the number of rows that can be displayed, such as ROWS = 10, tableA 10 line can be displayed. More than 10 lines, you need to drag the scroll bar to browse.

3.Name, the name of the text box, this must be inevitably, because the text must be used when the text is stored. 4.WARP, when Warp = “OFF” indicates that the text is not automatically wrapped in the text area, and of course, the default is automatic. This parameter is generally used. 5.Style, this is a very practical parameter, which can be used to set the background color of the text box, the scroll color, and the form, the frame color, the size of the input font, and so on.

6.Class, generally used to call the settings inside the external CSS.


Gets the wrap and space in the TextArea tag:

Problem: Get the format (wrap, space) within the TextArea tag, deposit into the database, The basic format can be retained when the show is displayed.

Solving the idea:

IE9 or more, FF, Chrome change behavior \ n, IE7-8 change behavior \ r \ n, space is \ s

So you need to use Replace to replace the \ n and \ r \ n of different browsers to

, replace the \ s space to HTML & nbsp

Note: If you use jQuery Val () Gets the value of TextArea, the value obtained does not contain the carriage return (\ r) character. However, if the value is passed to the server via XHR, the carriage return (\ r) character will be retained (or is added by the browser, but does not include the carriage return (\ r) in the original data).

This example has been replaced with \ r and \ r \ n. The actual effect is not affected, just pay attention to it.

The code is as follows:


DOCUMent.GtelementByid (“btn”). OnClick = function () {var strcontent = document.getlementByid (“text”). Value; Alert (“Strcontent before processing is \ r \ r \ n” + strcontent); strContent = strcontent. Replace (/ \ r \ n / g, ‘

‘); // IE9, ff, chromeStrContent = strcontent.replace (/ \ n / g, ‘

); // IE7-8strContent = strcontent. Replace (/ \ S / g, ”); // Space Processing Alert (“HTML code after conversion is \ r \ n” + strcontent); Document.getElementByid (“Show”). InnerHtml = strcontent;};

How to get all the contents of the wrap and space in the Textarea tag, thank you for reading! I believe everyone has a certain understanding, I hope to share the content of everyone, if you want to learn more knowledge, please pay attention to Tumi Yun Industry News Channel!

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment