jquery ui get id of droppable element, when dropped an item

前端 未结 4 1869
刺人心
刺人心 2020-12-04 14:39

How we get the id of droppable element, when dropped an item? Here i use jquery ui and asp.net mvc.

 

        
      
      
      
4条回答
  •  囚心锁ツ
    2020-12-04 15:04

    jQuery UI's droppable API manual mentions how to get the "dropped-on-droppable" very "secretly" in the section of greedy option:

    event.target can be checked to see which droppable received the draggable element

    But note that event.target contains just a DOM element...

    Answer to your question

    You will be able to get the ID in your droppable's drop callback through the first parameter event.

    Pure JS

    Property: event.target.id - if ID is not set: empty string ""
    Attribute: event.target.getAttribute('id') - if ID is not set: null

    jQuery

    Property: $(event.target).prop('id') - if ID is not set: empty string ""
    Attribute: $(event.target).attr('id') - if ID is not set: undefined

    Usage example

    
    

    Additional info

    Event
    jQuery's event system normalizes the event object according to W3C standards.
    The event object is guaranteed to be passed to the event handler (no checks for window.event required). It normalizes the target, relatedTarget, which, metaKey and pageX/Y properties and provides both stopPropagation() and preventDefault() methods.

提交回复
热议问题