我已經在我的網站中實現了JQuery拖放插件。它工作得很好,但是,我試圖訪問正在排序的div,但發現很難選擇它。JQuery拖放:訪問Sortable()Divs
所以,我試圖選擇每個列中的每個「dragbox」。這通常是簡單的工作,但出於某種原因,我無法訪問它,並且無法在FireBug中看到它。
有沒有人有任何想法如何使用循環訪問cols中的「dragbox」項?謝謝大家!
編輯:
我也用find()方法,並沒有工作
<div class="column" id="col1">
<div class="dragbox" id="item1" >
control goes here
</div>
<div class="dragbox" id="item1" >
<!-- control goes here -->
</div>
</div>
<div class="column" id="col2">
<div class="dragbox" id="item3" >
<!-- control goes here -->
</div>
</div>
我使用下面的JQuery:
$('.column').sortable({
connectWith: '.column',
handle: '.widget-header-holder',
cursor: 'move',
placeholder: 'placeholder',
forcePlaceholderSize: true,
opacity: 0.4,
stop: function(event, ui) {
$(ui.item).find('.widget-header-holder').click();
var sortorder = '';
$('.column').each(function() {
var itemorder = $(this).sortable('toArray');
var columnId = $(this).attr('id');
sortorder += columnId + '=' + itemorder.toString() + '&';
});
/*alert('SortOrder: ' + sortorder);*/
console.log(sortorder);
}
});
也許你想.find? $('。column')。find('。dragbox')。each ...,在你的情況下你可以做'$('。column')。each(function(){$(this).find(' '.dragbox')。each(...));' – Matt
是的,我已經使用查找,它不工作 – Funky
是找到或toArray應該工作,不知道爲什麼它不適合你。也許設置一個jsfiddle腳本並檢查。 – Matt