指定字符串过滤.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>

posted @ 2020-04-30 09:46  阿向向  阅读(200)  评论(0编辑  收藏  举报