2011-10-31 4 views
1

jquery를 사용하여 어떤 선택 상자가 기본값으로 설정되어 있는지 찾으려고합니다.선택 상자의 기본 이름 얻기

나는 많은 설정이 있습니다.

var selectBoxes = $('select', this.el); 
selectBoxes.each(function(){ 
    console.log("val = ", $(this).val()); 
}); 

각 선택 상자의 기본값을 제공하지만이 옵션이 속한 옵션을 찾으려고합니다.

//Select every `<select>` which is a child of this.el, and loop through it 
var selectBoxes = $('select', this.el); 
selectBoxes.each(function(){ 
    //`this` points to the select element 
    // The following declaration will define a HTMLOptionElement 
    var selectedOption = select.options[this.selectedIndex]; 
    var value = selectedOption.value;  //Recommended 
    //Alternatively: $(selectedOption).val(); 
}); 

선택한 옵션 요소의 jQuery 방법을 사용하려면, JQuery와의 객체를 포장 : 영업의 의견에 내 대답을 부연

+0

''select [i] .selectedIndex' 그리고''select [i] .options [select i] .selectedIndex]'옵션을 사용하십시오. –

+0

롭, 고맙다. – Chapsterj

답변

0

그것은해야한다 ..

var selectBoxes = $('select', this.el); 
selectBoxes.children().each(function(){ 
    console.log($(this).text()); 
}); 
0

생성자 : $(selectedOption).