Examples of jquery templates

  • 2020-03-29 23:41:18
  • OfStack

 
<body> 

<h1> World champions  QQ : 467713292</h1> 

<!--  The location label that places the template  --> 
<div id="contactContainer"></div> 

<!--  Defines the content layout of the template   And define the fields to display  --> 
<script id="contactTemplate" type="text/html"> 
<div> 
 The name : {{= name }} <br /> 
 Mobile phone no. : {{= phone }} 
</div> 
</script> 
//Reference two js

 
<script src="Scripts/jquery-1.4.2.js" type="text/javascript"></script> 
<script src="Scripts/jquery.tmpl.js" type="text/javascript"></script> 
<script type="text/javascript"> 

var contacts = [ 
{name:" World champions ", phone:"467713292"}, 
{name:" Dances with wolves ", phone: "206-555-7878" }, 
{name:" A novice programmer ", phone: "415-555-8888" } 
]; 

//This is all it takes to populate the json data defined above into the template and render it

 
$("#contactTemplate").render(contacts).appendTo("#contactContainer"); 
</script> 
</body> 

Related articles: