写了这么久的web程序,还没好好整理过javascript方面的东西,每次要用到什么东西都是满世界的找,在曾经的项目里,在google里到处搜,下次还是做好一个存放一个,从这里开始整理吧.
1、替换字符串中
所有字符
<script type="text/javascript">
function strReplace(search, replace, str) {
var regex = new RegExp(search, "g");
return str.replace(regex, replace);
}
var aa = new Array();
aa.push(",","。","!","、","?",";");
var aa1 = new Array();
aa1.push(",",".","!",",","?",";");
var str = "你好,大家都在忙什么?有空来玩,再见。"
for(var i=0; i<aa.length; i++){
var ostr = ""+aa[i];
var nstr = ""+aa1[i];
str = strReplace(ostr,nstr,str);
}
document.write(str);
</script>
posted on 2006-06-16 21:34
简易 阅读(64)
评论(0) 编辑 收藏