xxxxxxxxxx
<!DOCTYPE html>
<html>
<title>JavaScript replace() 方法字符串替换修饰符gi - 基础教程(div.cn)</title>
<body>
<h1>JavaScript replace() 方法</h1>
<p>点击该按钮,以不区分大小写的方式将全局变量" to be"替换为" ZZZ":</p>
<button onclick="myFunc()">Click</button>
<p id="result"></p>
<script>
function myFunc() {
var str1 = 'The question is TO BE, or not to be, that is to be.';
var str2 = str1.replace(/to be/gi, 'ZZZ');
document.getElementById('result').innerHTML = str2;
}
</script>
</body>
</html>