解决javascript中replace只能替换第一个


replace如果替换数据时,默认只替换第一个。

  如果在替换的时候加上: / 替换内容 /g 就能实现全部替换

  例如:

function change(strvalue){
strvalue = strvalue.replace(/&/g,"&");
strvalue = strvalue.replace(/&lt;/g,"<");
strvalue = strvalue.replace(/&gt;/g,">");
strvalue = strvalue.replace(/&quot;/g,""");
strvalue = strvalue.replace(/&#39;/g,"'");
return strvalue;
}


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3