/************************************************************** Replace: Returns a string in which a specified substring has been replaced with another substring a specified number of times.
Parameters: Expression = String expression containing substring to replace Find = Substring being searched for. Replace = Replacement substring.
Returns: String Sample: alert(Replace("12345645","45","99")) //Return "12399699" ***************************************************************/ function Replace(Expression, Find, Replace) { var temp = Expression; var a = 0;
for (var i = 0; i < Expression.length; i++) { a = temp.indexOf(Find); if (a == -1) break else temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length)); }
Replace: Returns a string in which a specified substring has
been replaced with another substring a specified
number of times.
Parameters:
Expression = String expression containing substring to
replace
Find = Substring being searched for.
Replace = Replacement substring.
Returns: String
Sample:
alert(Replace("12345645","45","99")) //Return "12399699"
***************************************************************/
function Replace(Expression, Find, Replace)
{
var temp = Expression;
var a = 0;
for (var i = 0; i < Expression.length; i++)
{
a = temp.indexOf(Find);
if (a == -1)
break
else
temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length));
}
return temp;
}
JasonJHu(品牌) 系统有 replace 函数的, 没有必要再写一个, 效率上不行
要全部替换就这样
<script>
var strText = new String() ;
strText="<input type=text><input type=submit>"
alert( strText ) ;
var re = new RegExp ("<IMG", "gi") ;
var newstr = strText.replace(re, "<IMG width") ;
alert( newstr ) ;
</script>Right 了吧
哈哈 :)