日期:2014-05-16  浏览次数:20364 次

js给数字用豆号分节

自己写的js给数字豆号分节,来提高自己

转自:http://www.ok22.org/art_detail.aspx?id=56 (可直接运行)

?

Html代码 运行
  1. < html > ??
  2. < body > ??
  3. < table ? border = "1" ? cellspacing = "5" ? id = "sp" > ??
  4. < tr > < td > 12345436267.89 </ td > < td > 3402.89 </ td > < td > 3402 </ td > </ tr > </ table > ??
  5. < script > ??
  6. function?formatNumber(num){???
  7. if(!/^(\+|-)?(\d+)(\.\d+)?$/.test(num)){return?num;}???
  8. var?a ?=? RegExp .$1,? b ?=? RegExp .$2,? c ?=? RegExp .$3;???
  9. var?re ?=? new ?RegExp().compile("(\\d)(\\d{3})(,|$)");???
  10. while(re.test(b))?b b ?=?b.replace(re,"$1,$2$3");???
  11. return?a?+""+?b?+""+?c;???
  12. }???
  13. function?spl(){??
  14. var?tdvalue = document .getElementById("sp").getElementsByTagName("td");??
  15. var?std = "" ;??
  16. var?rstr = "" ;??
  17. for(j = 0 ;j < tdvalue.length ;j++)??
  18. {?std = "" ;??
  19. std = tdvalue [j];??