replace

<!DOCTYPE html>
<html>
<body>

<p>Replace 功能</p>

<button onclick="myFunction()">点击</button>

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

<script>
function myFunction() {
    var str = document.getElementById("demo").innerHTML;
    var txt = str.replace("Paul","Ringo");
    document.getElementById("demo").innerHTML = txt;
}
</script>

</body>
</html>

posted @ 2018-10-25 17:09  命力  阅读(170)  评论(0)    收藏  举报