您好,登錄后才能下訂單哦!
插件 github 地址 https://github.com/KanbanSolutions/jquery-tmpl
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="../../js/jquery-1.11.2.min.js"></script> <script type="text/javascript" src="../../js/jquery.tmpl.js"></script> <script type="text/javascript"> $(function(){ var data = {username:"xiao",foods:[{name:"apple"},{name:"bear"}]}; $("script[name=template]").tmpl(data).appendTo("div[name=content]"); }); </script> <script name="template" type="text/x-jquery-tmpl"> username:{%= username%}<br/> {%if foods.length == 0 %} There is no foods. {%else%} There are {%= foods.length%} kinds of foods.<br/> favourite foods are below.<br/> {%each(i,food) foods%} <div>{%= food.name%}</div> {%/each%} {%/if%} </script> </head> <body> <div name="content"></div> </body> </html>
Note : 最好將模板信息放在script標簽里邊,不然{%if%}表達式如果有>或<可能會有問題。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。