文章详细
js给数字用豆号分节
 2010/12/15 21:46:20 评论:0人 阅读次数:8922

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

 

<html>
<body>
<table border="1" cellspacing="5" id="sp">
<tr><td>12345436267.89</td><td>3402.89</td><td>3402</td></tr></table>
<script>
function formatNumber(num){ 
if(!/^(\+|-)?(\d+)(\.\d+)?$/.test(num)){return num;} 
var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3; 
var re = new RegExp().compile("(\\d)(\\d{3})(,|$)"); 
while(re.test(b)) b = b.replace(re,"$1,$2$3"); 
return a +""+ b +""+ c; 
} 
function spl(){
var tdvalue=document.getElementById("sp").getElementsByTagName("td");
var std="";
var rstr="";
for(j=0;j<tdvalue.length;j++)
{ std="";
std=tdvalue[j];
rstr=formatNumber(std.innerHTML); 
std.innerHTML=rstr
}
}
spl();
</script>
</body>
</html>
如需转载请注明出处:http://www.86y.org/art_detail.aspx?id=56【js给数字用豆号分节】幸凡学习网
0
 
相关文章
推荐文章
Created By Charry-May 3,2010
粤ICP备10093478号-1
顶部