0

i want to get the url for the image. For this i use this code

 $(function () {
     $('.li').mousedown(function (e) {
         if (e.which === 1) {
             $(".li:nth-child(n) a").attr('id');
             var clickId = this.id;
             var n = clickId - 1;
             var imageurl = $(".fadein img:eq(" + n + ")").attr("src");
             alert(imageurl);
         }
     });
 });

problem is next. slide show displays a second image. I click on the first position and i'm getting the current url of image which is displayed. How to get the url of first image ?

who knows!!!!!! why i don't get an url of the image by id?

4

1 回答 1

0

尝试这样的事情:

$(function () {
 $('.circle li').on('click',function (e) {
         var id = $(this).attr("id"); //this is the number of id
         var elem = $(this).attr("id") -1; //this is modified id to table elements
     var imageurl = $('.fadein img:eq('+elem+')').attr('src');
     alert( 'the no. '+id +' have url ' + imageurl);

 });
});

这是示例 http://jsfiddle.net/CzmTA/3/

并记住 jquery 中元素的位置是一个数组,它从 0 而不是 1 开始我认为这应该有效

于 2013-11-08T16:09:37.497 回答