将文本中的Paul替换为Runoob

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="cover.css">
</head>
<body>
<button onclick="myFunction()">点我</button>
<p id="demo">Paul,Paula,paul,sPaul,Paul</p>
<script>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var txt = str.replace(/\bPaul\b/g,"Runoob");
document.getElementById("demo").innerHTML = txt;
}
</script>

</body>
<html>

 

 

posted on 2018-10-28 21:26  ylsunny  阅读(87)  评论(0编辑  收藏  举报