代码示例:(标识:jsck_replace_1)
<!DOCTYPE html>
<html>
<body>

<h1>JavaScript 字符串</h1>

<h2>replace() 方法</h2>

<p>replace() 方法在字符串中搜索值或正则表达式,并返回已替换值的新字符串。</p>

<p id="demo">Visit Microsoft!</p>

<script>
let text = document.getElementById("demo").innerHTML; 
document.getElementById("demo").innerHTML = text.replace("Microsoft", "(www.sou-xun.com)");
</script>

</body>
</html>
运行结果: