1
<p>单击按钮将段落中的“blue”替换成“red”。</p>
2
<p id="demo">Mr Blue has a blue house and a blue car.</p>
3
<button onclick="myFunction()">点我</button>
4
<script>
5
function myFunction() {
6
var str = document.getElementById("demo").innerHTML;
7
var n = str.replace(/blue/gi, "red");
8
document.getElementById("demo").innerHTML = n;
9
}
10
</script>