Jquery Jssor滑块:获取当前照片的名称(href)?

Jquery Jssor滑块:获取当前照片的名称(href)?,jquery,jssor,Jquery,Jssor,使用“Jssor滑块”,我想在div中显示当前照片的名称(或“href”)。 诸如此类: HTML: <div u="slides" ... > <!-- All the photos --> </div> <div id="photoName_Container"></div> 怎么做?谢谢尼古拉斯。 <div u="slides" ... > <div><img id="image_

使用“Jssor滑块”,我想在div中显示当前照片的名称(或“href”)。 诸如此类:

HTML:

<div u="slides" ... >
    <!-- All the photos -->
</div>

<div id="photoName_Container"></div>
怎么做?谢谢尼古拉斯。


<div u="slides" ... >
    <div><img id="image_0" u="image" src="url1" /></div>
    <div><img id="image_1" u="image" src="url2" /></div>
    ...
</div>


<script>

    jQuery(document).ready(function ($) {
        var options = {

            $AutoPlay: true,                                   //[Optional] Whether to auto play, to enable slideshow, this option must be set to true, default value is false
            $DragOrientation: 3                                //[Optional] Orientation to drag slide, 0 no drag, 1 horizental, 2 vertical, 3 either, default value is 1 (Note that the $DragOrientation should be the same as $PlayOrientation when $DisplayPieces is greater than 1, or parking position is not 0)
        };

        var jssor_slider1 = new $JssorSlider$("slider1_container", options);

        function SlideParkEventHandler(slideIndex, fromIndex) {
            var src = $("#image_" + slideIndex).attr("src");
            //do something here
        }

        jssor_slider1.$On($JssorSlider$.$EVT_PARK, SlideParkEventHandler);
    });
</script>
... jQuery(文档).ready(函数($){ 变量选项={ $AutoPlay:true,//[可选]是否自动播放,若要启用幻灯片放映,此选项必须设置为true,默认值为false $DRAGORIENTION:3//[可选]拖动幻灯片的方向,0不拖动,1水平,2垂直,3任意,默认值为1(请注意,$DISPLAYPIGES大于1或停车位置不为0时,$DRAGORIENTION应与$PLAYORIENTION相同) }; var jssor_slider1=新的$JssorSlider$(“slider1_容器”,选项); 函数SlideParkEventHandler(slideIndex,fromIndex){ var src=$(“#图像”+slideIndex).attr(“src”); //在这里做点什么 } jssor_slider1.$On($JssorSlider.$EVT_PARK,SlideParkEventHandler); });
我自己回答。我找到了如何在“img”标签中自动放置带有数字的“id”:


jQuery(文档).ready(函数($){
var jssor_slider1=新的$JssorSlider$(“slider1_容器”,选项);
$(#container_photos div”)。每个(function(){//包装“img”的“div”
var number=$(this).index();//获取slideIndex!!
$(this).children(“img[u=image]”).attr(“id”,“image”+number);
});
函数SlideParkEventHandler(slideIndex,fromIndex){
var src=$(“#图像”+slideIndex).attr(“src”);
$(“#photoName_Container”).html(src);
}
jssor_slider1.$On($JssorSlider.$EVT_PARK,SlideParkEventHandler);
});

问题解决了

尼古拉斯·博克尔完美地回答了这个问题。但是有一个小的编辑(花了整整一个小时来达到这一点:()),这可能重要,也可能不重要

$("#container_photos div").each(function(){ // the "div" wrapping the "img"

        var number = $(this).index(); // here the index start from 1 !!
        $(this).children("img[u=image]").attr("id","image_" + number); // so the "id" would be image_1 for the first slide.;

});
但是在函数SlideParkEventHandler中,slideIndex从0开始,因此我们得到第一张幻灯片的undefinedsrc。因此,我们需要从上述代码中的数字中减去1,以获得正确的图像id

$("#container_photos div").each(function(){ // the "div" wrapping the "img"

        var number = $(this).index(); // here the index start from 1 !!
        $(this).children("img[u=image]").attr("id","image_" + **(number-1)**); // so the "id" would be image_1 for the first slide.;

});

这个答案很好,但我必须在每个“img”标签上都放一个带数字的“id”?非常非常乏味!!有更简单的解决方案吗?
$("#container_photos div").each(function(){ // the "div" wrapping the "img"

        var number = $(this).index(); // here the index start from 1 !!
        $(this).children("img[u=image]").attr("id","image_" + number); // so the "id" would be image_1 for the first slide.;

});
$("#container_photos div").each(function(){ // the "div" wrapping the "img"

        var number = $(this).index(); // here the index start from 1 !!
        $(this).children("img[u=image]").attr("id","image_" + **(number-1)**); // so the "id" would be image_1 for the first slide.;

});