2011-09-02 33 views
0

我想在刪除div#Draggable時運行函數insertHouse()。我無法設法使其工作。你可以看到我試圖從底部的第二行調用它。我究竟做錯了什麼?jQuery - 刪除div時調用函數

<img src="images/door1.jpg" id="draggable"> 
<div id="items"></div> 

// Place house; 
function insertHouse() 
{ 
blablabla 
} 

$(init); 

function init() { 
    $('#makeMeDraggable').draggable(); 
    $('body').droppable({ 
    drop: handleDropEvent 
    }); 
} 

function handleDropEvent(event, ui) { 
    function insertHouse(); 
} 
+1

'函數insertHouse();'是一個語法錯誤。直接刪除'function'和/或直接將'insertHouse'設置爲drop handler:'drop:insertHouse'。 –

回答

0

下面的代碼將工作...

function init() { 
    $('#makeMeDraggable').draggable(); 
    $('body').droppable({ 
drop: function(event, ui){ 
insertHouse(); 
} 
    }); 
} 
+0

你的代碼也應該工作,只需將調用從'function insertHouse()'改爲'insertHouse()' – Varun