我对这段代码感到困惑
<!DOCTYPE html>
<html>
<body>
<p>Click the button to replace "Microsoft" with "W3Schools" in the paragraph
below:</p>
<p id="demo">Microsoft Visit Microsoft! Microsoft visit visit microsoft Visit Visit
Visit Visit</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = document.getElementById("demo").innerHTML.replace(/ Visit |Microsoft/gi, ' test ');
}
</script>
</body>
</html>
当点击按钮时有些文字没有改变,如果再次点击会改变
第一次点击后
test test test ! test test visit test test Visit test Visit
第二次点击后
test test test ! test test test test test test test test
为什么有些词第一次没有改变?真挚地