用模版生成HTML的的框架jquery.tmpl使用详解

2020-05-23 06:01:14易采站长站整理

        </div>
        <h3>Two</h3>
        <div>
            And <em>more</em> <b>content</b>…
        </div>
    {{/wrap}}
    </script>
<script id=”tableWrapper” type=”text/x-jquery-tmpl”>
    <table cellspacing=”0″ cellpadding=”3″ border=”1″><tbody>
        <tr>
            {{each $item.html(“h3”, true)}}
                <td>
                    ${$value}
                </td>
            {{/each}}
        </tr>
        <tr>
            {{each $item.html(“div”)}}
                <td>
                    {{html $value}}
                </td>
            {{/each}}
        </tr>
    </tbody></table>
    </script>
 <script type=”text/javascript”>
        $(function () {
            $(‘#myTmpl’).tmpl().appendTo(‘#wrapDemo’);
        });
    </script>

$data $item $item代表当前的模板;$data代表当前的数据。

 实例:


<div id=”div_item_data”></div>
<script id=”item_data” type=”text/x-jquery-tmpl”>
     <div style=”margin-bottom:10px;”>
    <span>${$data.ID}</span>
    <span style=”margin-left:10px;”>${$item.getName(” “)}</span>
   </div>
</script>
<script type=”text/javascript”>