首页
技术博客
登录
6mi
u
盘
搜
搜 索
技术博客
js replace(a,b)之替换字符串中所有指定字符的方法
js replace(a,b)之替换字符串中所有指定字符的方法
tech
2026-08-09
2
js replace(a,b)之替换字符串中所有指定字符的方法
var str = 'abcadeacf'; var str1 = str.replace('a', 'o'); alert(str1); // 打印结果: obcadeacf var str2 = str.replace(/a/g, 'o');//g是重点,如果替换的为‘/’,需要转义,吧/a/g替换为'/\//g' alert(str2); //打印结果: obcodeocf,
转载请注明原文地址:https://tech.qufami.com/read-28499.html
最新回复
(
0
)