RegExp( replace()的示例 )
此代码功能为替换掉单词Paul为Ringo:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<button onclick="myFunction()">try it!</button>
<p id="demo1">Paul,Paula,Pauline,paul,Paul</p>
<script>
function myFunction()
{
var str = document.getElementById("demo1").innerHTML;
var txt = str.replace("Paul","Ringo");
document.getElementById("demo1").innerHTML = txt;
}
</script>
</body>
</html>