[英]How to get data-id when carousel glyphicon is clicked
我需要獲取一個ID,但是它在滑塊中,並且我可以訪問的唯一click事件是箭頭,但是它們不能使用圖像的唯一ID。 我知道必須有一種遍歷div的方法,但是現在我的聯盟有點偏離了。 我確實嘗試了所有發現或遇到的嘗試,但到目前為止都沒有成功。
滑塊的代碼
<div id="myCarousel" class="carousel slide fluid col-md-6 col-md-offset-3" data-ride="carousel" style="height:95%;background-color: #000;">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active" style="border:1px solid #febe27;margin-bottom:125px;"></li>
{% for storyItem in craft.entries.section('stories').find() %}
{% for previewImage in storyItem.slideshowImage %}
<li data-target="#myCarousel" data-slide-to="1" style="border:1px solid #febe27;margin-bottom:125px;"></li>
{% endfor %}
{%endfor%}
</ol>
<div class="carousel-inner" role="listbox" style="height:87%;position:relative;">
<div class="item active">
{% for storyItem in craft.entries.section('stories').limit(1) %}
{% for previewImage in storyItem.slideshowImage %}
<div id="{{storyItem.id}}" class="imgContentWrapper 1" data-id="{{storyItem.id}}"><a href="#"><img src="{{ previewImage.url('slideshowImage') }}" alt="" border="0" /></a>
</div>
{% endfor %}
{%endfor%}
</div>
{% for storyItem in craft.entries.section('stories').offset(1) %}
{% for previewImage in storyItem.slideshowImage %}
<div class="item ">
<div id="{{storyItem.id}}" class="imgContentWrapper" data-id="{{storyItem.id}}"><a href="#"><img src="{{ previewImage.url('slideshowImage') }}" alt="" border="0" /></a>
</div>
</div>
{% endfor %}
{%endfor%}
</div>
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true" style="margin-left:-25px;"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true" style="margin-right:-25px;"></span>
<span class="sr-only">Next</span>
</a>
我正在嘗試在glyphicon“點擊”上的div(有兩個活動項和常規項)中抓取{{storyItem.id}}。
任何幫助是極大的贊賞。
這應該可以解決問題...
$('.glyphicon-chevron-left, .glyphicon-chevron-right').on('click', function() {
var id = $('.carousel-inner').find('item.active').find('.imgContentWrapper').data('id');
});
我想a.carousel-control
與您的圖片位於同一#myCarousel
div中。 如果是這樣,您可以遍歷父級並找到所需的圖像,如下所示:
$('.carousel-control').on('click', function() {
var imageId = $(this).parent().find('#your_image_selector');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.