首页 > 其他 > 详细

Ringo替换Paul

时间:2018-10-28 19:54:18      阅读:161      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Paul,Ringo</title>
    <link rel="stylesheet" type="text/css" href="">
</head>
<body>

    <p>Replace the first "Paul" and the last "Paul" with "Ringo" in the paragraph below:</p>

    <button onclick="myFunction()">Try it</button>

    <p id="demo1">Paul, Paula, Pauline, paul, Paul </p>

<script>
    function myFunction(){
    var str1 = document.getElementById("demo1").innerHTML;
       var txt1 = str1.replace(/Paul,/g,"Ringo,");
       var txt2 = txt1.replace(/, Paul /g,", Ringo ");
       var txt3 = txt2;
       document.getElementById("demo1").innerHTML = txt3;
    }
</script>
    
</body>
</html>

 

效果如图:

技术分享图片

 

 

技术分享图片

 

Ringo替换Paul

原文:https://www.cnblogs.com/DJOSIMON/p/9866744.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!