2013-05-20 4 views
0

접을 수있는 세트가 있고 각 접을 수있는 세트에 listview을 추가했습니다.이미지 교환 jquery mobile

list view 나는 list item 클릭시 image button를 전환 할

var li = '<li data-icon="false" data-theme="a" ><h5><img src="unselected.png" width="auto" height="3%" >' + row['Date'] + '</h5></li>';  

아래와 같이 동적으로 생성, 그리고 난 내 list view 하나 개의 항목 만 지금 이런 식으로

$('ul').children('li').off('click').on('click', function() { 
    var currentimg = $(this).find('img').attr('src'); 
    if (currentimg == "unselected.png") { 
     $(this).find('img').attr('src', 'selected.png'); 
    } else { 
     $(this).find('img').attr('src', 'unselected.png'); 
    } 
});  

을하고있는 중이해야 selected.png 다른 사람은 unselected.png이어야합니다. 어떻게 할 수 있습니까?

감사합니다 :)

답변

2

근무 예 : http://jsfiddle.net/Gajotres/3H4g8/

$(document).on('pagebeforeshow', '#index', function(){ 
    $('ul').children('li').off('click').on('click', function() { 
     var clickedItem = $('ul li').index(this); 
     var currentimg = $(this).find('img').attr('src'); 
     if (currentimg == "http://beaglehappy.com/wp-content/uploads/2012/03/beagle-puppy-training-50x50.jpg") { 
      $(this).find('img').attr('src', 'http://profile-a.xx.fbcdn.net/hprofile-snc6/276874_259622770824534_1630725890_q.jpg'); 
     } else { 
      $(this).find('img').attr('src', 'http://beaglehappy.com/wp-content/uploads/2012/03/beagle-puppy-training-50x50.jpg'); 
     } 

     $("li").each(function(index) { 
      var loopLi = $(this);    
      if(clickedItem != index) {    
       loopLi.find('img').attr('src', 'http://profile-a.xx.fbcdn.net/hprofile-snc6/276874_259622770824534_1630725890_q.jpg'); 
      } 
     });   

    });  
}); 
관련 문제