Home > Web Front-end > JS Tutorial > body text

Example of using replace() method to find characters_javascript skills

WBOY
Release: 2016-05-16 17:18:37
Original
973 people have browsed it

One function commonly used for text input boxes is to replace specified characters. JavaScript has a very useful method replace(), which can be used to use the specified characters in an alternative character set. The

replace() method allows you to specify the character or set of characters you wish to replace by using a string or regular expression; this is the first argument to the method. The second argument is the character that Xie Ang is replaced with. The second argument is usually just a replacement string (replacement character set), but it can be a function that determines what the replacement string should be - if it is a function, the return value should be used as the replacement string. The syntax of hiding the replace() method can be any of the following:

Copy code The code is as follows:

string.replace(oldSubString,newSubString);
string.replace(regEx,newSubString);
string.replace(regEx,finction());

Simple example below Use the replace() method on a text area and look for the string "URL" in the text box. After finding the string "URL", the method replaces it with the string "ABC". Here is the example:
Copy the code The code is as follows:


The replace() method

Replacing character strings:


< form name="myForm">