博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jQuery Template 简单使用
阅读量:6910 次
发布时间:2019-06-27

本文共 1117 字,大约阅读时间需要 3 分钟。

插件 github 地址 https://github.com/KanbanSolutions/jquery-tmpl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!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%}表达式如果有>或<可能会有问题。

 本文转自 antlove 51CTO博客,原文链接:http://blog.51cto.com/antlove/1639903

转载地址:http://cbbcl.baihongyu.com/

你可能感兴趣的文章
【BZOJ】4873: [Shoi2017]寿司餐厅
查看>>
【CodeForces】913 D. Too Easy Problems
查看>>
二十四种设计模式:命令模式(Command Pattern)
查看>>
Django 创建项目笔记
查看>>
Java B2B2C多用户商城 springcloud架构 - commonservice-eureka 项目构建过程(八)
查看>>
Apache Maven Compiler Plugin
查看>>
leetcode-852-山脉数组的峰顶索引
查看>>
EL表达式和JSTL标签快速入门
查看>>
微信小程序踩坑指南
查看>>
你了解HTTPS,但你可能不了解X.509
查看>>
SCRIPT1010: 缺少标识符 常见原因
查看>>
jquery里面获取div区块的宽度与高度
查看>>
Bootstrap 类解析
查看>>
查看MySQL是否在运行
查看>>
【转】从MVC到前后端分离
查看>>
七夕专场-A题
查看>>
JS----获取DOM元素的方法(8种)
查看>>
Android应用开发中三种常见的图片压缩方法
查看>>
项目总结12:bootstrap-select下拉框模糊搜索
查看>>
SCRUM 是一个用于开发和维护复杂产品的框架
查看>>