template模板demo

<body>
    <div id="content">

    </div>
    <div id="content2">
        
    </div>
    <div id="content3">
        
    </div>
</body>
<script src="https://cdn.nikm.cn/js/template.js"></script>
<script src="https://cdn.nikm.cn/js/jquery.js"></script>
<script id="test" type="text/html">
    <h1>{{user.name}}</h1>
</script>
<script id="test2" type="text/html">
    {{each data v k}}
    <div>
        <span>{{v.name}}</span>
        <span>{{v.age}}</span>
    </div>
    {{/each}}    
</script>
<script id="test3" type="text/html">
{{if name1=='张三'}}
{{name1}}
{{/if}}
</script>
<script>
    var data = {
        'user': {
            'name': 'test'
        }
    };
    var html = template('test', data);
    console.log(html);
    document.getElementById("content").innerHTML = html;
</script>
<script>
    $.get('./test19.php',function(res){
        console.log(res);
        var html2 = template('test2', {data:res});
        console.log(html2);
        document.getElementById("content2").innerHTML = html2;
    },'json')
</script>
<script>
    var data3 = {
        'name1':'张三',
        'name2':'李四'
    };
    var html3 = template('test3',data3);
    console.log(html3);
    document.getElementById('content3').innerHTML = html3;
</script>
Last modification:August 20th, 2019 at 10:52 am
If you think my article is useful to you, please feel free to appreciate

One comment

  1. 于长野

    Hi,网站很好看呀

Leave a Comment

简爱博客