2013-04-25 2 views
-1

나는 같은 클래스의 콤보 5 개가 있습니다.선택한 사용자 값을 가진 comboxbox를 찾는 방법

내가 콤보가

내 시도 그들에 값 5를 선정했다 그중 찾을 싶습니다

$(document).ready(function($){ 
    previous = 0; 
    $('.check').focus(function() { 
     // Store the current value on focus and on change 
     previous = this.value; 
    }).change(function() { 
     // Do something with the previous value after the change 
     //change previous container with value 
     newVal = this.value; 
     //alert(previous); 
     console.log('Old Val: ' + previous + '- new val:' + newVal); 
     $lst = $('.ranking option[value=' + newVal + ']:selected'); 
     console.log('one ' + $lst.length); 

     // Make sure the previous value is updated 
     previous = this.value; 
    }); 

}); 
+0

코드가 추가 ..... – KoolKabin

답변

3

jQuery를 자신의 값, 이름을 기반으로 요소를 필터링하기 쉽게 만드는 등

$('.check').filter(function(){ 
    return $(this).find('option:selected').val() == 5; 
}) 

위의 함수는 값 5 만 선택된 선택 요소 만 반환합니다.

여기 안녕 확인할 수있는 바이올린 http://jsfiddle.net/N2bya/

0

내 당신이 필요로하는 모든 코드 완료 jsFiddle. 여기

전체 코드의 조각입니다 :

$('select').change(function(){ //trigger for the change event of the comboboxes 

    var selectedIndex = $(this).prop("selectedIndex"); 
    if(selectedIndex === 4) { //basically the 5th item as it is zero indexed 
     alert('you have chosen the fifth item'); 
    } 
}); 


$('#checker').click(function(){ //for checking of all items with item number 5 selected 
    indexChecker(); 
}); 

var indexChecker = function(){ 
    var controlList =[]; 
    $('select').each(function(){ 
     if($(this).prop("selectedIndex") === 4){ 
      controlList.push($(this).attr('id')); 

     } 
    }); 
    alert('You have selected the fifth element in <select> element with id of : '+ controlList); 
}; 
관련 문제