type 为 text/template 的 script 块
选择性加载dom,可以在html中把需要使用的dom如下所示
<script id="temp_gallery_tab" type="text/template">
<ul class="gallery_tab clearfix pt20">
<li class="selected">我的应用</li>
<li>百宝箱</li>
</ul>
</script>
文档加载时不会显示出来,在需要显示时使用js动态显示
如下:
var tab = $("#temp_gallery_tab").html();
appBox.append(tab);
自定义简单模板
var item = '<li name="recentApp" appid="{id}"><img src="{src}" width="48" height="48"><span>{name}</span></li>';
var $item = $(item.replace('{id}', app.id).replace('{src}', app.icon).replace('{name}', app.name));
appDom.append($item);