【前端】制作一个handlebars的jQuery插件

(function($) {
    var compiled = {};
    $.fn.handlebars = function($srcNode, data) {
        // 取出模版内容
        var src = $srcNode.html();
        // 编译模版
    	var template = Handlebars.compile(src);
        // 传入数据,得到html并显示
    	this.html(template(data));
    };
})(jQuery);

// 使用
$('#content').handlebars($('#template'), { name: "Alan" });
原文地址:https://www.cnblogs.com/forzhaokang/p/5530004.html