<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="../resource/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../resource/js/jquery.tmpl.min.js"></script>
</head>
<body>
<script id="myTemplate" type="text/x-jquery-tmpl">
<tr><td>${'${'}Name}</td><td>${'${'}ReleaseYear}</td></tr>
</script>
<table cellspacing="0" cellpadding="3" border="1">
<tbody id="rows">
</tbody>
</table>
</body>
<script>
$(function () {
var movies = [
{ "Name": "The Red Violin", "ReleaseYear": "1998" }, //{Name:"",release,""}使用${Name}获取不到
{ "Name": "Eyes Wide Shut", "ReleaseYear": "1999" },
{ "Name": "The Inheritance", "ReleaseYear": "1976" }
];
console.log($( "#myTemplate" ).tmpl( movies ));
$( "#myTemplate" ).tmpl(movies).appendTo('#rows');
});
</script>
</html>
注意:在json文件中name位置的是双引号,遗留个问题就是当Name这个不是用双引号括起来就像官网上上面的例子一样的时候,使用${Name}获取不到值,至今未懂,大神看到的话,请留言解惑,未来我懂的话继续补充,谢谢
jquery.tmpl()小例子2
最新推荐文章于 2018-05-30 15:13:02 发布