【www.gdgbn.com--中文酷站】

我们用正常的replace替换中文是替换不了,下面我们利用new regexp来实现中文替换。

<script>
function   replaceexp()
{
      var   stringname   =   "数据 ";
      var   stringvalue   = "va ";
      var   expressionvalue   =   "数据+数据-数据 ";
    expressionvalue   =   expressionvalue.replace(new   regexp(stringname, "g "),stringvalue)
      alert(expressionvalue);
}
</script>

js replace 与replaceall实例用法

 stringobj.replace(rgexp, replacetext)
   
   参数
   stringobj
   
   必选项。要执行该替换的 string 对象或字符串文字。该字符串不会被 replace 方法修改。


更多详细内容请查看:http://www.111cn.net/wy/99/js_replace_replaceall.htm

本文来源:http://www.gdgbn.com/kuzhan/28537/