jQuery中template(模板)应用例子

来源:互联网 发布:制作手机电子书软件 编辑:程序博客网 时间:2024/05/19 10:41
<!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>
  
<script id="movieTemplate" type="text/x-jquery-tmpl"> 
    <li><b>${Name}</b> (${ReleaseYear})</li>
</script>


<ul id="movieList"></ul>


<script type="text/javascript">
var movies = [
    { Name: "The Red Violin", ReleaseYear: "1998" },
    { Name: "Eyes Wide Shut", ReleaseYear: "1999" },
    { Name: "The Inheritance", ReleaseYear: "1976" }
];


/* Render the template with the movies data and insert
the rendered HTML under the "movieList" element */
$( "#movieTemplate" ).tmpl( movies ).appendTo( "#movieList" );
</script>


</body>
</html>