jQuery Template and Data Linking
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <script type="text/javascript" src="jquery-1.4.2.js"></script> <script type="text/javascript" src="jquery.tmpl.js"></script> <script type="text/javascript"> $(function(){ var contacts= [ { name:"dannis wu吴1",phone:"10733-13453"}, { name:"dannis wu吴2",phone:"20733-13453"}, { name:"dannis wu吴3",phone:"30733-13453"}, { name:"dannis wu吴4",phone:"40733-13453"} ]; $("#productTemplate").render(contacts).appendTo("#dvContainer"); }); </script> </head> <body> <div id="dvContainer"></div> <script id="productTemplate" type="text/html"> <div style="border:solid 1px red" > Name: {{= name}} <br> phone: {{= phone}} <!--注意=号与 phone 之间一定要有一个空格--> </div> </script> </body> </html>
jQuery Templates, Data Link, and Globalization Accepted as Official jQuery Plugins