#前端 (引入bootstrap)
<div class="lunbotu">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<a href=""><img class="banner" src="" alt="..."></a>
<div class="carousel-caption">
</div>
</div>
<div class="item">
<a href=""><img class="banner" src="" alt="..."></a>
<div class="carousel-caption">
</div>
</div>
<div class="item">
<a href=""><img class="banner" src="" alt="..."></a>
<div class="carousel-caption">
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button"
data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button"
data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
#script
#通過ajax的get請求向后端要數(shù)據(jù)
#$(function () {}這個事件是等所有的頁面加載完成才執(zhí)行,是$(document).ready(function()的簡寫
$(function () {
$.ajax({
url:'/get_banner/',
method:'get',
success:function (data) {
$.each(data,function (k,v) {
$('.banner')[k].src = v.img_url
$($('.banner')[k]).parent().attr('href',v.url)
$($('.banner')[k]).parent().next().html(v.msg)
})
}
})
})
#后端
def get_banner(request):
l1 = [
{'url':'http://hsgwh.huangshan.gov.cn/',
'img_url':'/static/img/banner1.jpg',
'msg':'<h3>黃山</h3><p>值得玩味的地方</p>'},
{'url': 'http://www.liriver.com.cn/',
'img_url': '/static/img/banner2.jpg',
'msg': '<h3>桂林</h3><p>桂林山水甲天下</p>'},
{'url': 'http://www.mount-tai.com.cn/layout_class_service_pic.aspx?id=222',
'img_url': '/static/img/banner3.jpg',
'msg': '<h3>泰山</h3><p>五岳之首</p>'},
]
return JsonResponse(l1,safe=False)
##做成列表是為了可以后期增刪改
輪播圖使用
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門招盲,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人嘉冒,你說我怎么就攤上這事曹货。” “怎么了讳推?”我有些...
- 文/不壞的土叔 我叫張陵顶籽,是天一觀的道長。 經(jīng)常有香客問我银觅,道長礼饱,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任究驴,我火速辦了婚禮镊绪,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘洒忧。我一直安慰自己蝴韭,他們只是感情好,可當我...
- 文/花漫 我一把揭開白布熙侍。 她就那樣靜靜地躺著罩句,像睡著了一般。 火紅的嫁衣襯著肌膚如雪仙辟。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼哥攘!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起侠姑,我...
- 正文 年R本政府宣布愁铺,位于F島的核電站,受9級特大地震影響似将,放射性物質(zhì)發(fā)生泄漏在验。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一堵未、第九天 我趴在偏房一處隱蔽的房頂上張望腋舌。 院中可真熱鬧块饺,春花似錦、人聲如沸雌芽。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽圆凰。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間大年,已是汗流浹背。 一陣腳步聲響...