2016-11-02 10 views
1

나는 두 개의 선택 상자가 있고 어떤 선택 상자가 트리거되는지 알고 싶습니다.jquery에서 선택 상자 이름 가져 오기

HTML 코드 :

<form id="property-filters" method="post"> 
    <select name="sel1"> 
    <option value="1">1</option> 
    <option value="2">2</option> 
    </select> 

    <select name="sel2"> 
    <option value="3">3</option> 
    <option value="4">4</option> 
    </select> 
</form> 

jQuery 코드 : 어떤 도움이 높게 평가되어

$(document).on('change', '#property-filters input, #property-filters select', function() 
{ 
//Get the name of the select box. 
} 

. 미리 감사드립니다.

+1

체크'this.name' –

답변

2

확인은 이벤트의 이름 속성은 DOM 객체를 발사했다.

$(document).on('change', '#property-filters input, #property-filters select',function() { 
    if(this.name == 'sel1'){ 
     // do the rest 
    }else if(this.name == 'sel2'){ 
     // do the rest  
    } 
}) 
+0

많은 감사 PRANAV을 할 수 있습니다. 그것은 효과가 있었다. –

+0

@PrithvirajMitra : 기꺼이 도와주세요. –

0

당신은

$('#property-filters select').change(function() { 
    alert($(this).prop('name')); 
}); 

확인 JSFiddle

관련 문제