<script>
function ReplaceAll(str, sptr, sptr1)
{
while (str.indexOf(sptr) >= 0)
{
str = str.replace(sptr, sptr1);
}
return str;
}
</script>
调用示例:
<script>
var mystring="中国VB网欢迎您的光临!";
document.write("替换前:"+mystring+"<br>");
mystring=ReplaceAll(mystring,"中国VB网","http://www.chinaVB.net")
document.write("替换后:"+mystring);
</script>