要完成的效果如下图

其中下面添加出来的订单号和订单总价可以看作是接口请求的数据

实现步骤:

1 下载template7:https://github.com/nolimits4web/template7/,下载后将dist目录下的template7.js拖入工程,如下图

  

其中启动页是index.html,样式布局页面在index.css,jquery是用来方便dom操作。

部分代码讲解:

重点部分在于index.js,它的代码也很简单如下


var jsonData = {
orderId: 100012345,
orderPrice: 1000.00
} // 点击添加订单按钮
function addOrder() {
// 获取html模板
var template = $('#template').html();
// 编译模板
var compiledTemplate = Template7.compile(template);
// 给模板设置数据
var html = compiledTemplate(jsonData);
// 将模板拼接到指定处
$(".content .order_list").last().append(html);
} // 点击删除订单按钮
$(document).on("click", ".content .order_list .order_item .delete_order", function () {
$(this).parent().parent().remove();
});
jsonData为测试数据,也可以看作是后台接口返回的数据。在html代码中已经将jsonData对应字段插入对应标签中。

demo下载地址:
https://github.com/LiJinShi/html_template7template7使用教程:
http://idangero.us/template7/#.WgPLEa2757M

最新文章

  1. Unable to determine if the owner (Domain\UserName) of job JOB_NAME has server access
  2. 【网络编程】——linux socket demo
  3. 每天php函数 - floatval() 获取变量的浮点值
  4. Kinect For Windows V2开发日志一:开发环境的配置
  5. POJ 1401 Factorial
  6. 多个div并排显示的居中问题——来自腾讯的一道面试题
  7. 利用花生壳在自己电脑上建立外网可访问的svn
  8. win10 uwp 保存用户选择文件夹
  9. MySQL查看数据库安装路径
  10. print_r print var_dump echo区别
  11. strcpy_s和strcpy()
  12. 【转】反编译D-Link路由器固件程序并发现后门
  13. ORACLE窗口函数
  14. 解决 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 问题
  15. mac java jdk 安装删除
  16. Autofs
  17. Android如何设置TextView的行间距、行高。
  18. JavaScript中hoisting(悬置/置顶解析/预解析) 实例解释,全局对象,隐含的全局概念
  19. [SQL]197. Rising Temperature
  20. 6 springboot Docker 部署

热门文章

  1. js学习--变量作用域和作用域链
  2. React——state
  3. Web前端和后端之区分,以及…
  4. 半个月学习的it内容
  5. 【集美大学1411_助教博客】团队作业1——团队展示&选题 成绩
  6. java--整理下关于static关键字的知识
  7. Java 第八周总结
  8. 201521123024 《Java程序设计》第13周学习总结
  9. LINUX - awk命令之NF和$NF区别 (转)
  10. 接口测试入门(3)--使用httpClient进行登录用例操作/set-cookies验证/ List<NameValuePair>设置post参数/json解析