artTemplate js模板引擎动态给html赋值

html放到$("#area").append(html);之前,否则文档流获取不到#area

<table width="90%" class="table" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th >
名字
</th>
<th >
价格
</th>
</tr>
</thead>
<tbody id="area">
</tbody>
</table>

<script src="template-web.js"></script>

<script id="aaa" type="text/html">
{{each Table as value i}}
<tr><td>{{value.Name}}</td><td>{{value.Price}}</td></tr>
{{/each}}
</script>

<script>

var json={

Table:[
{Name:'牛肉',Price:'50'},
{Name:'羊肉',Price:'59'},
{Name:'鸡肉',Price:'21'}
]
};

var html = template('aaa', json);
$("#area").append(html);

</script>

猜你喜欢

转载自www.cnblogs.com/uftwkb24/p/9997123.html