js 简易模板引擎 , 持续更新。。。

<script>

var _mytpl = (function(){

    var _verson = 1.0;

    return {

        _data:{},

        load:function(html,data){

            with(this){

                _data.html = html;

                _data.data = data;

            }

            return this;

        },

        exec:function(){

            var me = this , t = me._data.html;

            t = t.replace(/\{(\w)+\}/g,function(arg1, arg2){

                return me._data.data[arg2];

            });

            this._data.html = t;

            t = null;

            return this;

        },

        preview:function(){

            alert(this._data.html);

        }

    };

})();

var Insa =  _mytpl.load('<div>{a}+{b}</div>', {a:1,b:2}).exec().preview();

</script>

 

你可能感兴趣的:(模板引擎)