str.replace(/<img/gi, "<img width='200'");

解决方案 »

  1.   

    str.replace('<IMG','<IMG width');
      

  2.   

    str.replace('<IMG','<IMG width=200');
      

  3.   

    /**************************************************************
     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;
    }
      

  4.   

    zltostem(尘寞) 的代码有问题, 只能替换一个img 在JS里的替换与VBS里的replace是不一样的!!
    JasonJHu(品牌) 系统有 replace 函数的, 没有必要再写一个, 效率上不行
      

  5.   

    meizz(梅花雪) :呵呵说的对哈
    要全部替换就这样
    <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 了吧
    哈哈  :)