2014-02-21 2 views
2

텍스트로 드롭 다운 항목을 선택하려고합니다. 값이 매번 달라 지므로 값으로 선택할 수 없습니다. 선택으로텍스트에 따라 드롭 다운 옵션을 선택하십시오.

$("#rn_SelectionInput_7_attend_session_time option").each(function(){ 
     alert($(this).text()==radioValue);// this evaluate to true when a matching item is found 

    if($(this).text()==radioValue) 
    { 
     $("#rn_SelectionInput_7_attend_session_time").selectedIndex=$(this.index()); // this doesn't do anything 
    } 
    }); 

감사합니다,

답변

2

당신은 그것을 할 수있는 옵션 요소의 선택 속성을 설정할 수 있습니다

$("#rn_SelectionInput_7_attend_session_time option").filter(function() { 
    alert($(this).text() == radioValue); // this evaluate to true when a matching item is found 
    return $.trim($(this).text()) == radioValue 
}).prop('selected', true); 

데모 : Fiddle

  • filter() - 옵션을 찾을 수 주어진 텍스트가있는 요소
  • .prop() - 선택한 속성을 true로 설정하십시오.
+0

코드를 제공해 주셔서 감사합니다. 하지만 내가 아저씨에게 소품을 바꿀 때만 작동합니다. 어떤 아이디어? 이 브라우저는 구체적입니까? –

+0

@BishnuPaudel 사용 된 jQuery 버전에 따라 다릅니다 ... 사용 된 jQuery 버전 –

+0

브라우저별로 다르면 좋네요. 내가 지금 일하고있는 페이지는 1.4.2를 사용하고 나는 바꿀 수 없다. 고마워요. –

관련 문제