指定字符串过滤.html

<script type="text/javascript">
var str='asdasdasdasdasdasdasdasd'
//把字符串d替换成*
// var res=str.replace('d','*') //只能把第一个替换掉
//
// //把res的值重新赋值给str
// str=res
//
// var res=str.replace('d','*')
// str=res
//
// str=res
//
// var res=str.replace('d','*')

//以循环方式来进行替换
//使用while循环 //str.indexOf('d')!==-1 不等等于-1 证明有
while(str.indexOf('d')!==-1){
//进行替换
str=str.replace('d','*')

}

document.writeln(str) //as*as*as*as*as*as*as*as*
</script>

原文地址:https://www.cnblogs.com/d534/p/12806928.html