2013-09-30 3 views
0

선택 태그의 현재 요소의 매개 변수를 동적으로 사용해야합니다. (무언가) 여기에 onchange 이벤트에 전달 된 태그의 ID와 내 코드의 태그가 필요합니다.부모 ID를 사용하여 매개 변수를 전달하는 방법

function ToggleDropDown(id1,id2) 
{/* Code */} 


     controls += '<span class="ui-btn-text" id="globalSelect">' + options.data[0].GlobalFieldName + '</span>';   
     controls += '<select id="GlobalFieldName" onchange=ToggleDropDown("GlobalFieldName","globalSelect");>'; 
     jQuery.each(options.data, function (index) { 

그래서 이것을 사용하여 매개 변수를 전달하는 방법. * (무언가) 그래서 매번 현재 div의 ID를 얻을 수 있습니다. 예를 들어 : 당신은 참 부모 요소를 얻을 수 .parent()를 호출 한 후 현재의 요소에 액세스 할 수 $(this)을 사용할 수 있습니다

alert($(this).parent().attr('id')); 
+0

그렇게 보인다 추한 –

답변

1

. 나는 당신이 요구하는 것을 잘 모르겠지만, 이것은 작동하는 방법이다 :

HTML :

<div class="theParent"><a href="#" class="theChild">Click me</a></div> 

자바 스크립트 :

$('.theChild').click(function(){ 
    $(this).parent().hide(); // hides "theParent" 
    $(this).parent().attr('class'); // logs "theParent" to the console 
}); 

JsFiddle : JS 내에서 마크 업 http://jsfiddle.net/5GuED/

관련 문제