2013-04-24 3 views
0

이를 사용하여 선택한 텍스트 값을 얻는 방법을 나는 선택 box.I의 jQuery를에 선택한 옵션의 텍스트를 가져 오는 데 사용 필요는 jQuery를

$('#selectId :selected').text(); 
내가 할 수있는 방법을하건 위해 잘 작동

이 다음과 함께. 여기는 모든 클래스를 반복 선택 상자를 iterating 오전. 나는 다음 코드를 사용하지만 그것은 나를 위해 작동하지 않습니다.

$('.className').each(function(index,value){ 
    alert($(this :selected).text()); 
    }); 

그것은 오류를 SyntaxError: missing) after argument list

을주고있다 ... 사전에 잘못된 구문의

답변

1

날 .Thanks 도와주세요.

$('.className').each(function(index,value){ 
    alert($(this).find('option:selected').text()); 
}); 

또는 대안으로 : 당신은 사용할 수 있습니다 당신은 그것의 option:selected 다음 경고 텍스트를 가져 change의 경우에이 방법을 사용할 수 있도록

$('.className').each(function(index,value){ 
    alert($("option:selected", this).text()); 
}); 
+1

귀하의 첫 번째 대답은 또한 나 – PSR

+1

U 감사

$('.className').each(function(index,value){ if($(this).is(':checked')) { alert($(this).val());} }); 
PSR

0

.className 참조 모음 자체입니다 그것의.

$('.className').on('change', function(){ 
    alert($("option:selected", this).text()); 
}); 
0

사용하십시오이

나를 위해 노력하고 있습니다
+1

위해 노력하지만 난 이것을 사용할 수 있습니다 box.How 내가 선택 사용하고 – PSR