首页 > Web开发 > 详细

js thousand separator and change td content

时间:2017-11-02 21:01:02      阅读:237      评论:0      收藏:0      [点我收藏+]
js thousand seprator and change TD content

// integer 
function addCommas(n){
    var rx=  /(\d+)(\d{3})/;
    return String(n).replace(/^\d+/, function(w){
        while(rx.test(w)){
            w= w.replace(rx, $1,$2);
        }
        return w;
    });
}

//decimal
function thousandBitSeparator(num) {
        return num && num
            .toString()
            .replace(/(\d)(?=(\d{3})+\.)/g, function($0, $1) {
                return $1 + ",";
            });
}

// change table td content by getElementsByClassName()

function changeTDcontent(){
    var olist=document.getElementsByClassName("cl_id");
    for(var i=0;i<olist.length;i++){
        var c=olist[i].innerHTML;
        olist[i].innerHTML=addCommas(c);
    }
}

 

js thousand separator and change td content

原文:http://www.cnblogs.com/rojas/p/7774123.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!