javascript中的replaceAll功能。
请注意/Microsoft/g,就是这个小g
在本例中,我们将执行一次全局替换,每当 "Microsoft" 被找到,它就被替换为 "W3C":
<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, "W3C"))
</script>
输出:
Welcome to W3C! We are proud to announce that W3C
has one of the
largest Web Developers sites in the world.
本文介绍JavaScript中的全局替换功能,通过实例演示如何使用正则表达式的全局标志符g来进行字符串的全局替换操作。
7655

被折叠的 条评论
为什么被折叠?



