代码如下:
<!DOCTYPE html>
<html>
<body>
<h2>javascript Regular Expressions</h2>
<p>正则表达式把所有Paul替换成Ringo:Paul Puala Pualine paul Paul
</p>
<button onclick="myFunction()">疯狂点我</button>
<p id="demo">Paul Puala Pualine 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>