RegExp replace

Posted snowdeer

tags:

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

替换单词Paul为Ringo:

 

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
</head>
<body>
    <button onclick="myFunction()">click</button>

    <p id="ag1">Paul,Paula,Pauline,paul,Paul</p>
    
    <script>
        function myFunction()
        {
            var str = document.getElementById("ag1").innerHTML;
            var txt = str.replace("Paul","Ringo");
            document.getElementById("ag1").innerHTML = txt;
        }
    </script>
</body>
</html>


















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