2014-01-01 3 views
5

사용자가 색인에서 선택하는 드롭 다운 옵션의 색인 번호를 보내고 있습니다. 이제 특정보기를 다른보기에서 '선택됨'으로 선택하려고합니다. jQuery를 사용하여 만드는 방법? JQuery와 객체에 selectedIndex 설정 jQuery에서 드롭 다운의 SELECTED 속성을 설정하는 방법은 무엇입니까?

$('#book_selection').attr("disabled", "disabled"); 
$('#book_selection').selectedIndex = 1; 

하지만이 작동하지

...

답변

2

사용 prop() 방법은 실질적으로 아무것도하지 않습니다.

$('#book_selection').prop("disabled", true) 
        .prop('selectedIndex', 1); 

대안 : : 대신 attr 방법을 사용해야 특성을 prop 방법을 수정하기위한 jQuery를 1.6으로 그건 그렇고, 속성을 설정하기 위해 사용 .prop()

// Getting the DOM element object using bracket notation and `.get()` method 
$('#book_selection')[0].selectedIndex = 1; 
$('#book_selection').get(0).selectedIndex = 1; 
3

당신은을 설정할 필요로하는 인덱스를 사용하여 값을 입력하십시오. 따라서이 경우 .eq(index)이 도움이 될 것입니다.

시도,

$('#book_selection option').eq(1).prop('selected',true); 
관련 문제