js常用功能技巧函数

//CSS复合样式转成JS驼峰式
function cssStyle2DomStyle(sName) {
    return sName.replace(/-\w/g,function(match){
        return match[1].toUpperCase();
    })
}

//简易模板
function template(context,json){
    var str = document.querySelector(context).innerHTML;
    var re = /{{\s*(\w+)\s*}}/g;
    return str.replace(re,function(match,key){
        return json[key];
    })  
}

 

posted on 2018-07-31 23:00  vsmart  阅读(141)  评论(0编辑  收藏  举报