1.html

<!DOCTYPE html>
<html> <head>
<title>模板标签</title>
</head> <body>
<table id="tableData">
<tr class="firstLine">
<th></th>
<th>图片</th>
<th>图片名称</th>
<th>类型</th>
<th>大小</th>
<th>尺寸</th>
<th>上传日期</th>
<th>操作</th>
<th></th>
</tr>
</table>
</body>

2.js临时模板

<script type="text/template">
<tr mgid="{mgid}" mid="{mid}">
<td>
<input type="checkbox" mid="{mid}">
</td>
<td>
<a href="{localfile}" data-fancybox-group="button" class="fancybox-buttons">
<img src="{localfile}" style="width:45px;height:45px;">
</a>
</td>
<td>
<input type="text" class="input-large valid" value="{medianame}" name="medianame" mid="{mid}" readonly="readonly">
</td>
<td>{mediatype}</td>
<!-- 各位看官,自定义的三个属性在这里哦~~ -->
<td>{fsize}</td>
<td>{asize}</td>
<td>{atime}</td>
<td>
<a href="javascript:void(0);">重命名</a>
<a name="edit" localfile="{localfile}" href="javascript:void(0);">替换</a>
<a href="javascript:void(0);">删除</a>
<a title="设置为分组【{groupname}】的封面" groupname="{groupname}" mid="{mid}" href="javascript:void(0);">设置封面</a>
</td>
</tr>
</script>

 3.核心代码

<script>
/*将模板写入到html*/
$.ajax({
url: '/html/datas',
type: 'get',
cache: false,
dataType: "json",
success: function(dta) {
if (!dta || !dta.rows || dta.rows.length <= 0) {
return;
}
//获取模板上的HTML
var html = $('script[type="text/template"]').html();
var arr = [];
//对数据进行遍历
$.each(dta.rows, function(i, o) {
//自定义字段
o.atime = getFormatDate(o.uploadtime ? o.uploadtime : o.createtime, 'yyyy-MM-dd');
o.asize = (o.width && o.height) ? o.width + ' * ' + o.height : '-';
o.fsize = o.seizespace ? o.seizespace + '  KB' : '-';
arr.push(formatTemplate(o, html));
});
$('#tableData').append(arr.join(''));
}
});
</script> <script>
/*日期格式*/
function getFormatDate(xdate, format) {
try {
var format = format || 'yyyy-MM-dd HH:mm:ss';
var date = (xdate instanceof Date) ? xdate : new Date(parseInt(xdate.replace('/Date(', '').replace(')/', ''), 10));
var lang = {
'M+': date.getMonth() + 1,
'd+': date.getDate(),
'H+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds()
};
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (var key in lang) {
if (new RegExp('(' + key + ')').test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ?
lang[key] : ('00' + lang[key]).substr(('' + lang[key]).length));
}
}
return format;
} catch (e) {
return '-';
}
}
</script>

  

最新文章

  1. [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二
  2. 史上最详细的linux网卡ifcfg-eth0配置详解
  3. python学习笔记(4)--函数
  4. C#如何获取项目中的其他文件夹的路径
  5. canvas转盘抽奖
  6. maven添加远程私服
  7. [转]Session服务器配置指南与使用经验
  8. Hibernate 通过 Session 操纵对象
  9. CSS position, z-index
  10. MySQL &quot;replace into&quot; 的坑
  11. apache和php扩展问题
  12. 比较两个文件不同以及生成SQL插入语句
  13. 浅论Python密文输入密码的方法
  14. python从入门到实践-4章操作列表
  15. R语言仪表盘
  16. python之路——24
  17. mockito 异常Reason: java.io.IOException: invalid constant type: 18
  18. VMware虚拟机磁盘操作占用过高问题
  19. OpenCV入门之寻找图像的凸包(convex hull)
  20. Problem B: 类的初体验(II)

热门文章

  1. Mysql 数据库之修改标的结构
  2. iOS App Store上架新APP与更新APP版本
  3. Source Insight设置
  4. Dubbo学习
  5. 各种同步方法性能比较(synchronized,ReentrantLock,Atomic)
  6. LeetCode Power of Four
  7. CentOS 7.2 安装配置Samba服务器
  8. PHP:php知识小解
  9. Ubuntu 汉化时ubuntu software database is broken错误解决
  10. 替换jenkins上打包完成的安装包的方法