Home Web Front-end JS Tutorial Solution to the problem that the content submitted by textarea cannot be wrapped_Basic knowledge

Solution to the problem that the content submitted by textarea cannot be wrapped_Basic knowledge

May 16, 2016 pm 05:37 PM
textarea Solution

When we submit data through textarea on the page, the content we enter will be processed into a piece of content after submission. Even if we enter a lot of line breaks in the textarea, it will still be a piece of content after submission. So if we What should we do if we need to save the information we entered in the form we entered?

A major problem here is that when the page is displayed, the newline character is the
tag, and when the content is displayed in the textarea, the newline character is n. Here is a method to use js to input Line breaks in the content are converted to line breaks in the web page. Submit the money on the web page data and do the following processing.

Copy code The code is as follows:


also needs to be processed when displayed on the page, which is exactly the opposite of the above process:

Copy code The code is as follows :

content=content.replace('
','n');

The following is an explanation of the replace function of js:

Syntax:

stringObject.replace(regexp/substr,replacement)

The

replace() method is used to replace some characters with other characters in a string, or replace a substring that matches a regular expression.

1. Replace a single character

Copy the code The code is as follows:


2. Replace all specified characters present in the string (replace all)

Copy code The code is as follows:


The above /g is a regular expression, which shows that regular expressions can also be used in replace().

Of course there are more advanced usages of replace. You can get more advanced usages in the relevant documents.


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1246
24
What should I do if the mouse wheel fails and jumps up and down randomly? Share three solutions What should I do if the mouse wheel fails and jumps up and down randomly? Share three solutions Mar 13, 2024 pm 07:28 PM

The mouse is one of the most important computer peripherals. However, during use, the mouse wheel will inevitably fail or jump up and down, which greatly affects the user's operation. Is there any way to solve this problem? Let’s take a look at three ways to solve the problem of random jumping of the mouse wheel. Method 1: Check the mouse. Mouse produced by different brands have their own characteristics. Some mouse wheels have high sensitivity or low damping, which may cause the wheel to jump erratically. To determine if the problem is with the mouse itself, you can lightly touch the mouse wheel and watch the page move on the screen. If you find that your mouse scrolls too sensitively, you may want to consider buying a new mouse to fix the problem. Method 2: Check the mouse settings Improper mouse settings may cause the mouse wheel to jump randomly.

What to do if ntdll.dll error occurs in win11 What to do if ntdll.dll error occurs in win11 Jun 29, 2023 pm 01:02 PM

What should I do if ntdll.dll error occurs in win11? Many users of win11 system will encounter errors caused by missing dll files during use. However, if the error problem is caused by the loss of the ntdll.dll file, it will be very serious. The ntdll.dll file is a very important working file for Windows system control. If it is lost, it can easily cause the system to crash. Faced with this situation, what should we do? Woolen cloth? Below, the editor will bring you solutions to the ntdll.dll error in win11 system. To solve the ntdll.dll error in win11 system, press Windows+R to open and run. Type cmd and press Enter to open the command prompt. 2. in

Share methods to solve PyCharm failure to start Share methods to solve PyCharm failure to start Feb 20, 2024 am 09:46 AM

PyCharm is a powerful Python integrated development environment (IDE) that is widely used in the daily work of Python developers. However, sometimes we may encounter the problem that PyCharm cannot be opened normally, which may affect the progress of our work. This article will introduce some common problems and solutions when PyCharm cannot be opened, and provide specific code examples, hoping to help you solve these problems smoothly. Problem 1: PyCharm crashes or becomes unresponsive. Possible reasons: PyCh

Error 629 broadband connection solution Error 629 broadband connection solution Feb 20, 2024 am 08:06 AM

Solution to Error 629 Broadband Connection With the rapid development of Internet technology, broadband has become an indispensable part of our daily lives. However, sometimes we may encounter some problems while using broadband, such as Error 629 Broadband Connection Error. This error usually causes us to be unable to access the Internet normally and brings a lot of inconvenience. In this article, we will share some methods to solve Error 629 Broadband Connection to help you solve this problem quickly. First, Error 629 broadband connection issues are usually caused by network configuration or driver issues

Share three solutions to why Edge browser does not support this plug-in Share three solutions to why Edge browser does not support this plug-in Mar 13, 2024 pm 04:34 PM

When users use the Edge browser, they may add some plug-ins to meet more of their needs. But when adding a plug-in, it shows that this plug-in is not supported. How to solve this problem? Today, the editor will share with you three solutions. Come and try it. Method 1: Try using another browser. Method 2: The Flash Player on the browser may be out of date or missing, causing the plug-in to be unsupported. You can download the latest version from the official website. Method 3: Press the "Ctrl+Shift+Delete" keys at the same time. Click "Clear Data" and reopen the browser.

What to do with BSOD error code 0xc0000001 in Win11 system What to do with BSOD error code 0xc0000001 in Win11 system Jul 02, 2023 am 08:13 AM

What to do with BSOD error code 0xc0000001 in Win11 system? In our daily use of computers, we will inevitably encounter computer problems, large and small. Recently, some users have encountered the BSOD error code 0xc0000001, which is very troublesome. For this, the editor has prepared a solution below. We will Get up and take a look. Solution steps for Win11 system BSOD error code 0xc0000001 Perform startup repair in Recovery mode 1. First, create bootable media for Windows 11 and use the media to boot the PC. 2. On the next screen, click Repair your computer. 3. You will now reach the system recovery options screen. 4. When choosing one

Common problems and solutions to pyqt5 installation errors Common problems and solutions to pyqt5 installation errors Jan 19, 2024 am 10:00 AM

With the popularity of Python, PyQt5 has become one of the first choice tools for many people for rapid GUI development. However, installation problems are inevitable. The following are several common problems with PyQt5 installation and their solutions. The error message when installing PyQt5 is that the sip module cannot be found. This problem usually occurs when using pip to install PyQt5. The reason for this error is the lack of dependencies on the sip module, so you need to install the sip module manually first. Enter the following code on the command line: pipinsta

PHP Deprecated: Function split() is deprecated - Solution PHP Deprecated: Function split() is deprecated - Solution Aug 17, 2023 pm 05:36 PM

PHPDeprecated: Functionsplit()isdeprecated-Solution When developing with PHP, we may encounter the following warning message: PHPDeprecated: Functionsplit()isdeprecated. What this warning means is that the split() function has been deprecated and its use is no longer recommended in the latest PHP versions. This article will explore this problem and provide solutions

See all articles