2010-09-04 29 views
0

降我沒有下降div的ID在滴上的另一個DIV 我得到的id_droppable我卻沒有得到id_dropped DIV 警報id_dropped給不確定的結果拖動和jQuery的

請幫助我驗證我的代碼並糾正我的錯誤。

$(".full-circle").droppable({ 
    accept: ".unseated_guest", 
    drop: function(event, ui) { 
     var id_droppable = this.id; 
     alert(id_droppable); 
     var id_dropped = ui.id; 
     alert(id_dropped); 
     var name=document.getElementById("div_name_0").value; 
     $(this).css("background-color","red"); 
     $(this).append(ui.draggable); 
     //$(this).draggable('disable'); 
     } 

    }); 

回答

0

ui參數不具有id屬性,因爲它是該元件爲藥物的參考。你需要得到id,比如ui.draggable.attr('id'),或者你喜歡得到元素的id的任何方法。

$(".full-circle").droppable({ 
    accept: ".unseated_guest", 
    drop: function(event, ui) { 
     //Stuff above 
     var id_dropped = ui.draggable.attr('id'); 
     alert(id_dropped); 
     //Stuff below 
     } 

    }); 
0

內滴處理程序,$(this)是可投放,ui.draggable是可拖動(作爲jQuery對象)。因此,對於可放開:

$(this).attr('id'); 
// or 
this.id; 

而且可拖動:

ui.draggable.attr('id'); 
// or, for the sake of symmetry: 
ui.draggable[0].id; 
+0

這是工作的感謝你們倆 – shahul 2010-09-04 06:30:27