首页 > Web开发 > 详细

js中replace的用法(两种常用举例,还有好多用法不一一列举)

时间:2017-02-11 16:40:10      阅读:323      评论:0      收藏:0      [点我收藏+]

1、替换特定字符

<html>
<body>

<script type="text/javascript">

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

</script>
</body>
</html>
2、全局替换

<html>
<body>

<script type="text/javascript">

var str="Welcome to Microsoft! ";
str=str + "We are proud to announce that Microsoft has ";
str=str + "one of the largest Web Developers sites in the world.";
document.write(str.replace(/Microsoft/g, "W3School"));

</script>

</body>
</html>

 

js中replace的用法(两种常用举例,还有好多用法不一一列举)

原文:http://www.cnblogs.com/jianxingjianyuan/p/6389254.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!