1.引入我们所需要的js包
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script type="text/javascript" src="js/jsrender-min.js"></script>
2.编写我们要输出内容的div
<div id="result"></div>
3.编写我们的数据
<script>
var data = [
{
"title": "山水图",
"imgpath":"http://pic17.nipic.com/20111111/7953751_140357624000_2.jpg",
'alink':"http://pic17.nipic.com/20111111/7953751_140357624000_2.jpg",
"showPic":true
},{
"title": "山水画",
"imgpath":"http://pic29.nipic.com/20130525/8960079_091008529373_2.jpg",
'alink':"http://pic29.nipic.com/20130525/8960079_091008529373_2.jpg",
"showPic":true
}
];
var templates = $.templates("#contentarea");
var htmlOutput = templates.render(data);
$("#result").html(htmlOutput);
</script>
<script type="text/jsrender" id="contentarea">
<div class="content">
<em>name:</em>{{:title}}
{{if showPic && imgpath }}
<a href={{:alink}} target='_blank'> <img src='{{:imgpath}}' width='100' height='100' /></a>
{{/if}}
</div>
</script>
(注:3和4的顺序可以颠倒过来)