插件 github 地址 https://github.com/KanbanSolutions/jquery-tmpl

    
    
    
    
    
        $(function(){            var data = {username:"xiao",foods:[{name:"apple"},{name:"bear"}]};            $("script[name=template]").tmpl(data).appendTo("div[name=content]");        });        
        username:{%= username%}
        {%if foods.length == 0 %}            There is no foods.        {%else%}            There are {%= foods.length%} kinds of foods.
            favourite foods are below.
            {%each(i,food) foods%}                
{%= food.name%}
            {%/each%}        {%/if%}        

Note : 最好将模板信息放在script标签里边,不然{%if%}表达式如果有>或<可能会有问题。