How to remove characters in JavaScript: First use the input tag to create a string input box and set its id attribute to myinput; then create a button button and bind the onclick click event; then create the del function in js; Finally, use the replace method to replace the string.
The operating environment of this article: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
Create a new html file, named test.html, to explain how to use js to remove specified characters from a string.
In the test.html file, use the input tag to create a string input box and set its id attribute to myinput.
In the test.html file, use the button tag to create a button with the button name "Remove www characters".
In the test.html file, bind the onclick event to the button button. When the button is clicked, the del() function is executed. [Recommended learning: js basic tutorial]
In the test.html file, in the js tag, create a del() function, in the function Inside, use getElementById() to obtain the input object, and then use the value attribute to obtain the content of the input box.
In the test.html file, use the replace() method to replace the "www" string with nothing, save the replaced string in the res variable, and finally , use the alert() method to output the results.
Open the test.html file in the browser, enter the string, click the button, and view the output results.
The above is the detailed content of How to remove characters in javascript. For more information, please follow other related articles on the PHP Chinese website!