[英]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.