2012-03-19 1 views
0

내가 여러 낙하 할 영역이 놓습니다. .?

답변

1

난 당신이

drop: function(event, ui) { 
     alert(this.id); 
    } 

당신은 내부 this을 사용할 수 있습니다

여기 바이올린 http://jsfiddle.net/r5rzX/

+0

감사 니콜라 :) 기능이 호출을 만들기로 모든 것을 jQuery를 사용할 필요가 없습니다 – user1184100

0

(그래서 당신은 이제 드롭 가능한 한 사용 된)이 낙하 할의 id을 찾기 위해 할 수있는 생각 handleElement 드롭은 드롭 된 것을 가져옵니다. ID를 데이터 속성에 저장해야합니다. 그러나 그러나 이것은 당신을 위해 작동합니다

for(j=0; j<2; j++) { 
    $('#dropElement' + j).droppable({   
     drop : handleElementDrop 
    }); 

} 

function handleElementDrop(event, ui) { 
    alert(this."id".replace("dropElement","")) 
} 

http://jsfiddle.net/Aspaq/

+0

비싸다 :'$ (this) .attr ("id") 대신'this.id'를 사용한다. –

+0

고마워! 나는 갱신 할 것이다. –

1

당신은 요소 내에서 모든 데이터 (단지 integeres, 심지어 배열 또는 객체)를 수송하기 위해 jQuery의 데이터() 함수를 사용할 수 있습니다 ..

을 예를 들어

:

for(j=0; j<2; j++) { 

    $('#dropElement' + j).data('mykey', myData); // set data 

    $('#dropElement' + j).droppable({   
     drop : handleElementDrop 
    }); 
} 

function handleElementDrop(event, ui) { 

    var myData = $(this).data('mykey'); // get data 

} 
관련 문제