Iam은 JQuery-select2 버전 3.5를 사용하여 구현 된 드롭 다운 상자를 사용합니다.옵션 목록에서 JQuery-select2 드롭 다운의 선택된 값을 변경하는 방법 JQuery를 사용하는 인덱스 번호
$("#fieldId").prop("selectedIndex",1)
과 같이 목록에서 선택한 2 번째 항목을 JQuery를 사용하여 설정하고 싶습니다.
가능합니까? 당신이 select
드롭 다운 메뉴를 의미하는 경우 사전에
감사
Iam은 JQuery-select2 버전 3.5를 사용하여 구현 된 드롭 다운 상자를 사용합니다.옵션 목록에서 JQuery-select2 드롭 다운의 선택된 값을 변경하는 방법 JQuery를 사용하는 인덱스 번호
$("#fieldId").prop("selectedIndex",1)
과 같이 목록에서 선택한 2 번째 항목을 JQuery를 사용하여 설정하고 싶습니다.
가능합니까? 당신이 select
드롭 다운 메뉴를 의미하는 경우 사전에
감사
$('#fieldId').select2("val",$('#fieldId option:eq(1)').val());
/*By using eq(), the index number should be calculated from 0*/
같은 것을 달성 할 수
또는
$('#fieldId').select2("val",$('#fieldId option:nth-child(2)').val());
/*By using nth-child(), the index number should be calculated from 1*/
이 유용 할 수 있습니다
귀하의 답변은 correc but.already 이것을 사용하고 주석에 언급되어 있습니다. 어쨌든 당신의 답을 다른 사람들을 돕기 위해 받아들이십시오. – Ponnarasu
는이 문제
<select>
<option>1st item</option>
<option selected>2nd item</option>
<option>3rd item</option>
</select>
편집을 해결해야합니다 당신이
$('select option:nth-child(2)').attr('selected', true);
지금까지 시도 무엇 ... – prashant
$ ("# fieldID가가") 소품 ("selectedIndex의를", 1).; – Ponnarasu