• layui.laytpl如何从外部引入模板文件


    首页 index.html
    <body>
        <div id="hello"></div>
        <script src="./lib/layui/layui.js"></script>
        <script>
            layui.use('layer', function(){ 
                var $ = layui.$;
                // 加载hello组件(会自动绑定组件对应的dom上)
                $("#hello").load("./components/hello.html");
            });
        </script>
    </body>
    组件 hello.html
    <script id="demo" type="text/html">
        <h3>{{ d.title }}</h3>
    </script>
    <script>
        var data = { //数据
            "title": "helloword"
        }
        var getTpl = demo.innerHTML
            , view = document.getElementById('hello');
    
        layui.use('laytpl', function () {
            var laytpl = layui.laytpl;
            laytpl(getTpl).render(data, function (html) {
                view.innerHTML = html;
            });
        })
    </script>
  • 相关阅读:
    hdu1507
    zoj1654
    hdu2444
    poj3692
    hdu1150
    hdu1151
    poj2771
    hdu3829
    hdu4619
    hdu4715
  • 原文地址:https://www.cnblogs.com/dshvv/p/13037399.html
Copyright © 2020-2023  润新知