日期:2014-05-20 浏览次数:20832 次
<script> String.prototype.replaceAll = function (AFindText,ARepText){ raRegExp = new RegExp(AFindText,"g"); return this.replace(raRegExp,ARepText); } alert("axxxbxxxxcxxxxx".replaceAll("x", "_")) </script>
------解决方案--------------------
一楼写的是很好的,请看我下面的实例代码:
<script language="javascript" type="text/javascript">
String.prototype.replaceAll = function (AFindText,ARepText){
raRegExp = new RegExp(AFindText,"g");
return this.replace(raRegExp,ARepText);
}
var str = "123,456,789,4";
alert(str.replaceAll(",",""));
</script>
运行结果:1234567894
------解决方案--------------------
写一个方法:
function deleDot(){
var str = "1,2,3";
var newStr = "";
for(var i=0; i<str.length; i++){
if(str.charAt(i) != ","){
newStr += str.charAt(i);
}
}
alert(newStr);
}