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>
posted @ 2018-11-02 10:41  alive*  阅读(113)  评论(0编辑  收藏  举报