art-template var render = template.compile(source);

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <script src="js/mb.js" type="text/javascript" charset="utf-8"></script>
        <script src="js/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
        <title></title>
    </head>
    <body>
        
            <div id="div_complie">
                
            </div>
            
            
            <script id="l" type="text/html">
                {{each $data}}
                <span style="display: inline-block;margin:0rem 50px;" >
                    {{$value}}
                </span>            
                {{/each}}
                <div id="erji"></div>
            </script>
        <script>
            var nav=[1,2,3,4]
            var list=template("l",nav)
            document.getElementById("div_complie").innerHTML = list;
            
            
            $("span").click(function(){
                        var source = '<ur>' +
                '{{each list}}'+
                    '<li>索引:{{$index+1}}:{{$value}}</li>'+
                '{{/each}}'+
            '</ul>';
            var data = {
                list : ['電影','電視劇456','綜藝','音樂']
            };
            var render = template.compile(source);
            var html = render(data);
            $("#erji").append(html)
                
            })
    
        </script>
        
        
    </body>
</html>
相關文章
相關標籤/搜索