This article describes how to use the replace function in JavaScript to replace strings. It involves the use skills of the replace function in javascript and is very useful, for more information about how to use the replace function to replace strings in JavaScript, see the following example. Share it with you for your reference. The details are as follows:
JavaScript replaces the string with the replace function. The following code replaces Microsoft in Visit MicroSoft with jb51.net.
Click the button to replace "Microsoft" with "jb51.net" in the paragraph below:
Visit Microsoft!
Try itScript function myFunction () {var str = document. getElementById ("demo "). innerHTML; var n = str. replace ("Microsoft", "jb51.net"); document. getElementById ("demo "). innerHTML = n;} script
I hope this article will help you design javascript programs.