2011-05-13 44 views
2

只要它不是當前的可拖動對象,我就可以讓IE去除對象。這是在Chrome和Firefox上工作。有什麼我做錯了嗎?

<html> 
<head> 
    <script src="http://code.jquery.com/jquery-latest.js"></script> 
    <script src="http://code.jquery.com/ui/jquery-ui-git.js"></script> 
</head> 
<body> 
    <ul id="list"> 
    <li id="test-1" class="dropme">One</li> 
    <li id="test-2" class="dropme">Two</li> 
    </ul> 
    <div id="bucket" style="border:1px solid black"> 
     <p>Drop items here and they should be removed.</p> 
    </div> 
    <script> 
     $("#list").sortable({ 
     items: 'li' 
    }); 
    $('#bucket').droppable({ 
     drop: function(event, ui) { 
      $(ui.draggable).remove(); 
     }, 
     accept: '.dropme' 
    }); 
    </script> 
</body> 
</html> 
+0

ui.draggable返回的是什麼?在那個選擇器中,它不需要是所有可拖動的DOM元素的字符串?如果它忽略了這一點,我在UI文檔中找不到它。同樣給頁面一個DOCTYPE,因爲IE很可能處於怪異模式,並且不能正常工作。 – Dormouse 2011-05-13 16:52:10

+0

'ui.draggable'是大多數jQuery UI拖動事件中的當前拖動元素。實際上,它已經是一個jQuery對象,不需要執行'$(ui.draggable)'。 – DarthJDG 2011-05-13 17:01:34

+0

@達思。謝謝,每天都是學生! – Dormouse 2011-05-13 17:06:45

回答

2

在IE中ui.draggable和drop函數有點古怪。試試這個:

<html> 
<head> 
    <script src="http://code.jquery.com/jquery-latest.js"></script> 
    <script src="http://code.jquery.com/ui/jquery-ui-git.js"></script> 
    <script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script> 
</head> 
<body> 
    <ul id="list"> 
    <li id="test-1" class="dropme">One</li> 
    <li id="test-2" class="dropme">Two</li> 
    </ul> 
    <div id="bucket" style="border:1px solid black"> 
     <p>Drop items here and they should be removed.</p> 
    </div> 
    <script> 
     $("#list").sortable({ 
     items: 'li', 
     stop: function(event, ui) { 
      if (deleteMe) { 
         ui.item.remove(); 
         deleteMe = false; 
        } 
     } 
    }); 
    $('#bucket').droppable({ 
     drop: function(event, ui) { 
      deleteMe = true; 
     }, 
     accept: '.dropme' 
    }); 
    </script> 
</body> 
</html> 
+0

不錯的工作邁克....添加一個標誌是一個整潔的小動作+1 – Raja 2011-05-13 17:23:14

+0

這工作!非常感激。我討厭IE的特殊編碼! errr! – getSurreal 2011-05-13 17:59:47

+0

^x無窮大。非常感謝。 – Ken 2012-02-06 23:57:46