欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Underscore.js 的模板功能介紹與應(yīng)用

 更新時(shí)間:2012年12月24日 17:27:49   作者:  
Underscore是一個(gè)非常實(shí)用的JavaScript庫(kù),提供許多編程時(shí)需要的功能的支持,他在不擴(kuò)展任何JavaScript的原生對(duì)象的情況下提供很多實(shí)用的功能,需要了解的朋友可以詳細(xì)參考下
Underscore是一個(gè)非常實(shí)用的JavaScript庫(kù),提供許多編程時(shí)需要的功能的支持,他在不擴(kuò)展任何JavaScript的原生對(duì)象的情況下提供很多實(shí)用的功能。
無(wú)論你寫一段小的js代碼,還是寫一個(gè)大型的HTML5應(yīng)用,underscore都能幫上忙。目前,underscore已經(jīng)被廣泛使用,例如,backbone.js唯一強(qiáng)依賴的庫(kù)就是underscore.js。
今天主要討論Underscore 的前端模板功能。它的模板功能和前一篇介紹的javascript前端模板是一樣的。對(duì)數(shù)據(jù)的處理更加方便。寫了個(gè)小例,供大家參考學(xué)習(xí)。

完整實(shí)例下載
復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Underscore</title>
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no"/>
<link href="index.css" rel="stylesheet" type="text/css" />
<script src="jquery.js"></script>
<script src="underscore.js"></script>
</head>
<body>
</body>
</html>
<!--ace-template demo-->
<script id="t2" type="text/template">
<%_.each(datas, function(item) {%>
<div class="outer">
<div class="title">
<span ><%=item.film%></span>
</div>
<ul class="ul">
<%_.each(datas, function(item) {%>
<li>
<a href="<%=item.url%>">【<%=item.title%>】</a>
</li>
<%});%>
</ul>
</div>
<%});%>
</script>
<!--數(shù)據(jù) -->
<script>
var datas = [
{
title: "一九四二",
url: "http://www.dbjr.com.cn",
film:"電影1"
},
{
title: "少年派的漂流",
url: "http://www.dbjr.com.cn",
film:"電影2"
},
{
title: "教父",
url: "http://www.dbjr.com.cn",
film:"電影3"
},
{
title: "肖申克的救贖",
url: "http://www.dbjr.com.cn",
film:"電影4"
},
{
title: "3d2012",
url: "http://www.dbjr.com.cn",
film:"電影5"
}
];
$("body").html( _.template($("#t2").html(), datas));
</script>
<!--點(diǎn)擊下拉事件-->
<script type="text/javascript">
$('.ul').hide();
$('.ul>li:last-child').addClass('last-li');
$('body>div:first-child>ul').show();
$('.title').click(function(){
$(this).siblings().toggle();
$(this).parent().siblings().children('.bbs-nav-ul').hide();
}) $('.title').hover(function(){
$(this).toggleClass('hover');
})
$('.ul>li').hover(function(){
$(this).toggleClass('hover');
})
</script

相關(guān)文章

最新評(píng)論