zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    软件工程实践总结
    用户使用调查报告
    Beta 冲刺 随笔合集
    Beta 冲刺 七
    Beta 冲刺 六
    Beta 冲刺 五
    Beta 冲刺 四
    Beta 冲刺 三
    Beta 冲刺 二
    Beta 冲刺 一
  • 原文地址:https://www.cnblogs.com/dshvv/p/13037399.html
Copyright © 2011-2022 走看看