JS Replace

Posted azurite

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS Replace相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html>
<body>
 <button onclick="myFunction()">Try it</button>
 <p id="demo">Paul,Paula,paul,sPaul,Paul,Paul</p>
 <script>
  function myFunction() {
      var str = document.getElementById("demo").innerHTML;
      var txt = str.replace(/Paul/g,"Ringo");
      document.getElementById("demo").innerHTML = txt;
  }
 </script>
</body>
</html>














以上是关于JS Replace的主要内容,如果未能解决你的问题,请参考以下文章