<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
</head>
<body>
<ul id="movieList"></ul>
<script>
var movies = [
{ Name: "The Red Violin", ReleaseYear: "1998" },
{ Name: "Eyes Wide Shut", ReleaseYear: "1999" },
{ Name: "The Inheritance", ReleaseYear: "1976" }
];
var markup = "<li><b>${Name}</b> (${ReleaseYear})</li>";
/* Compile the markup as a named template */
$.template( "movieTemplate", markup );
/* Render the template with the movies data and insert
the rendered HTML under the "movieList" element */
$.tmpl( "movieTemplate", movies )
.appendTo( "#movieList" );
</script>
</body>
</html>
Jquery template 小demo
最新推荐文章于 2024-04-15 09:42:31 发布
本文介绍了一种利用jQuery模板插件将JSON数据格式的电影信息动态填充到HTML列表的方法。通过定义模板标记并结合jQuery的模板方法,可以轻松地为每部电影生成带有名称和发行年份的列表项。
754

被折叠的 条评论
为什么被折叠?



