1 //JQuery替換全部字符
<script> 2 String.prototype.replaceAll = function (targetStr, newStr) { 3 var sourceStr = this.valueOf(); 4 while (sourceStr.indexOf(targetStr) !== -1) { 5 sourceStr = sourceStr.replace(targetStr, newStr); 6 } 7 return sourceStr; 8 }; 9 </script>
//Jquery替換全部字符 replace升級 replaceAll
1 <script> 2 String.prototype.replaceAll = function (s1, s2) { 3 return this.replace(new RegExp(s1, "gm"), s2); 4 } 5 </script>