JavaScript使用replace函数替换字符串的方法
本文实例讲述了JavaScript使用replace函数替换字符串的方法。分享给大家供大家参考。具体如下:
<!DOCTYPE html> <html> <body> <p> Click the button to replace "Microsoft" with "jb51.net" in the paragraph below: </p> <p id="demo">Visit Microsoft!</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { var str=document.getElementById("demo").innerHTML; var n=str.replace("Microsoft","jb51.net"); document.getElementById("demo").innerHTML=n; } </script> </body> </html>
希望本文所述对大家的javascript程序设计有所帮助。
相关推荐
满地星辰 2020-09-16
有梦就能实现 2020-06-05
gcgl000hugang 2020-02-10
hellobabygogo 2020-03-06
wbingyang 2020-02-16
一对儿程序猿 2019-12-22
宿舍 2019-12-11
liangkaiping0 2011-09-23
niuyongaiai 2013-06-09
drise 2012-05-29
不懂 2019-06-28
shqhope 2020-06-23
WebVincent 2020-06-16
lynjay 2020-06-14
ajaxtony 2020-06-11
zhendeshifeng 2020-05-27
Yasin 2020-05-05
Darklovy 2020-04-16