2011-03-03 5 views
0

나는 다음과 같은 HTML했다 : 내가 jQuery를 아약스jQuery를 선택

<tr> 
    <td> 
    <img id='1' class='promote' src='/images/plus.png' /> 
    <span>0</span> 
    <img id='1' class='demote' src='/images/minus.png' /> 
    </td> 
    <td> 
    <img id='2' class='promote' src='/images/plus.png' /> 
    <span>0</span> 
    <img id='2' class='demote' src='/images/minus.png' /> 
    </td> 
... 
</tr> 

다음 사용하고 있습니다 : 내가 대신 사용해야의 jQuery 셀렉터의 조합 그래서

$('img.promote').click(function() { 
    $.ajax({ 
    url: '/promote/' + this.id, 
    success: function(data) { 
     $(???).text(data.rating); 
    }, 
    dataType: 'json' 
    }); 
}); 
$('img.demote').click(function() { 
    $.ajax({ 
    url: '/demote/' + this.id, 
    success: function(data) { 
    $(???).text(data.rating); 
    }, 
    dataType: 'json' 
    }); 
}); 

를, "??? " span 태그 사이의 텍스트를 변경 하시겠습니까? 아니면 내가 잘못하고있는거야? 고맙습니다.

+0

의 범위를 캐시 할 필요가 한 번에 스팬의 * 모든 * 변경을 시도하고 있습니까? 또는 단지 특정 하나? – guildsbounty

+0

그냥 하나, 등급 시스템의 일부입니다. – cheetah

답변

2

당신은 클릭 처리기

$('img.promote').click(function() { 
    var $span = $(this).siblings('span'); 
    $.ajax({ 
    url: '/promote/' + this.id, 
    success: function(data) { 
     $span.text(data.rating); 
    }, 
    dataType: 'json' 
    }); 
});