如何用原生js替换字符串中的某个字符(或字符串)为指定的字符串?

<html>

<head>
<title>我的第一个 HTML 页面</title>
</head>
<script type="text/javascript">

var str="Visit Microsoft!Microsoft sfs Microsoft"
document.write(str.replace(/Microsoft/g, "W3School"))

</script>


</html>

输出:

Visit W3School!W3School sfs W3School

猜你喜欢

转载自www.cnblogs.com/YuyuanNo1/p/9395154.html