JS Replace 全部替换字符 用法

<script language="javascript">
var r= "1\n2\n3\n";
//将字母\n替换成分号
alert(r.replace("\n",";"));

结果:1;2\n3\n 只替换了第一个
</script>

<script language="javascript">
var r= "1\n2\n3\n";
//将字母\n替换成分号
alert(r.replace(/\n/g, ";"));

结果:1;2;3; replace 的第一个参数可以是正则表达式,/g标识全文匹配。
</script>

文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 6 | 引用: 0 | 查看次数: 964
回复回复Jaxon[2019-07-12 04:54 PM | del]
You've got good knowlwdge at this point.
回复回复Kristen[2019-07-09 10:34 AM | del]
Extremely revealing looking onward to returning.
回复回复Korey[2019-07-02 00:25 AM | del]
Great website! It looks really professional! Keep up the helpful job!
回复回复Jeanne[2019-06-29 12:34 AM | del]
Quite useful, looking forward to coming back.
回复回复Isis[2019-06-26 03:02 PM | del]
With thanks for sharing this very good web site.
回复回复Michale[2019-06-25 07:31 PM | del]
Truly interesting, looking forward to returning.
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭