flio
::
首页
::
联系
:: ::
管理
0 Posts :: 6 Stories :: 6 Comments :: 0 Trackbacks
留言簿
(2)
给我留言
查看公开留言
查看私人留言
文章分类
信息安全
前端技术(2)
框架技术(2)
软件开发
软件架构
文章档案
2012年5月 (4)
搜索
最新评论
1. re: ajax+json渲染html
54
--14
2. re: ajax+json渲染html
4556fd
--7252
3. re: SpringMVC+hibernate3(2.mvc三层实现)
评论内容较长,点击标题查看
--zuidaima
4. re: SpringMVC+hibernate3(2.mvc三层实现) [未登录]
期待楼主 出整合hibernate的代码啊
--ken
5. re: SpringMVC+hibernate3(2.mvc三层实现)
哥又顶了
--x7
ajax+json渲染html
一直在寻找ajax如何渲染页面的东西。早期我的做法一般都是动态拼接html代码,这次设计到框架设计,考虑使用更好的技术,刚刚看到了一篇不错的文字,贴下来备忘
基于jQuery的AJAX和JSON实现纯html数据模板加载
www.diybl.com 时间 :
2011
-
07
-
30
作者:网络 编辑:hawk 点击:
44
[ 评论 ]
<
script type
=
"
text/javascript
"
>
$(document).ready(function ()
{
$(
"
#spnLoad
"
).html(
"
<font color=green>数据加载中……</font>
"
);
$.getJSON(
"
Handler.ashx?n=
"
+
Math.random(),function(data)
{
if
(data.length
>
0
)
{
$.each(data,function(index,json)
{
var row
=
$(
"
#template
"
).clone();
//
克隆一份模板
row.find(
"
#divPName
"
).html(json.FirstName);
//
替换标记内容
row.find(
"
#divCName
"
).html(json.LastName);
row.find(
"
#divID
"
).html(json.EmployeeID);
row.attr(
"
id
"
,index);
//
改变行的Id
row.appendTo(
"
#tableTemp
"
);
//
添加到模板的容器中
}
);
$(
"
#template
"
).css(
"
display
"
,
"
none
"
);
//
隐藏行模块
$(
"
#trLoad
"
).css(
"
display
"
,
"
none
"
);
//
隐藏提示行模块
}
else
{
$(
"
#spnLoad
"
).html(
"
<font color=green>没有查询到数据!</font>
"
);
}
}
);
}
);
</
script
>
html模板:
<
table cellpadding
=
"
1
"
cellspacing
=
"
1
"
border
=
"
0px
"
style
=
"
background-color:#000
"
width
=
"
600px
"
id
=
"
tableTemp
"
>
<
tr
>
<
td style
=
"
background-color:#fff
"
>
省份
</
td
>
<
td style
=
"
background-color:#fff
"
>
城市
</
td
>
<
td style
=
"
background-color:#fff
"
>
城市编号
</
td
>
</
tr
>
<
tr id
=
"
trLoad
"
style
=
"
background-color:#fff
"
><
td colspan
=
"
3
"
><
span id
=
"
spnLoad
"
></
td
></
tr
>
<
tr id
=
"
template
"
>
<
td style
=
"
background-color:#fff
"
id
=
"
divPName
"
></
td
>
<
td style
=
"
background-color:#fff
"
id
=
"
divCName
"
></
td
>
<
td style
=
"
background-color:#fff
"
id
=
"
divID
"
></
td
>
</
tr
>
</
table
>
posted on 2012-05-31 11:18
flio
阅读(2529)
评论(2)
编辑
收藏
所属分类:
前端技术
Feedback
#
re: ajax+json渲染html
2016-03-18 16:02
14
54
回复
更多评论
#
re: ajax+json渲染html
2016-03-18 16:02
7252
4556fd
回复
更多评论
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
相关文章:
基于jQuery的AJAX和JSON实现纯html数据模板(转载)
ajax+json渲染html
Copyright @ flio
Powered by:
.Text
and
ASP.NET
Theme by:
.NET Monster