替换富文本里的px为rem

var content = '23px'

content = content.replace(/(\d+)px/g, function(s, t) {
    s = s.replace('px', '');
    var value = parseInt(s) * 0.001; // 100px = 1rem
    return value + "rem"; //0.23rem
});    

 

posted @ 2017-08-18 11:41  Cynthia娆墨旧染  阅读(835)  评论(0编辑  收藏  举报