2011-04-27 102 views
0

我有可排序的對象,我需要記錄.next()對象的ID。第一次需要記錄的是當你使用對象(獲取.next()對象的ID)和第二次獲取ID .next()對象的位置時。我應該使用什麼Jquery mouseevent來獲取正確的值?

我可以使用mousedown獲取第一個.next()ID。

$(function() { 
    $("#sortable").sortable(); 
    $("#sortable").disableSelection(); 
}); 

$("li").live("mousedown",function(e) { 
    document.getElementById("result").innerHTML=($(this).next("li").attr('id')) 
}); 

但是,我可以使用什麼來獲取它放置後的.next()對象的ID?

爲了清楚起見,這裏是一個的jsfiddle文件:

http://jsfiddle.net/TSM_mac/pJbeB/

回答

1

Here's a live demo

下面的代碼

$(function() { 
    $("#sortable").sortable({ 
     start : function(event, ui) { 
      $('#result').html($(ui.item).next().next().attr('id')); 
      //we have to use .next().next() because jquery creates a dummy 
     }, 
     stop : function(event, ui) { 
      $('#result').html($(ui.item).next().attr('id')); 
     } 
    }); 
    $("#sortable").disableSelection(); 
}); 

注意使用next().next(),這是故意的。

看一看可用的事件/方法列表中的API與排序工作時:http://jqueryui.com/demos/sortable/

+0

真棒!!!!非常感謝。這很好 – TaylorMac 2011-04-27 05:10:43

0

我想鼠標懸停是你在找什麼。

$("li").live("mouseover",function(e) { 
     document.getElementById("result").innerHTML=($(this).next("li").attr('id')) 
    }); 
相關問題