edge旧版浏览器对一些js方法不是很兼容,经常出现各种js报错,从而导致显示出问题。今天在做项目的时候,出现了edge不兼容replaceAll方法从而导致报错,最终页面数据无法正常回显。
对此我们加了一个方法对此进行特殊处理,全局引入异常处理的js。
try{
"".replaceAll('',"")
}catch(e=>{
String.prototype.replaceAll=function(replaceStr,newStr){
return this.replace(new RegExp(replaceStr,'gm'),newStr)
}
})
//g 表示全局匹配
//m 表示多行匹配
作者:隋元超