我想使用此代码为我的Bootstrap应用程序创建拖放功能(我使用jQuery,jQuery UI和Bootstrap):
jQuery的:
jQuery(function($) {
var panelList = $('#draggablePanelList');
panelList.sortable({
// Only make the .panel-heading child elements support dragging.
// Omit this to make then entire <li>...</li> draggable.
handle: '.panel-heading',
update: function() {
$('.panel', panelList).each(function(index, elem) {
var $listItem = $(elem),
newIndex = $listItem.index();
$.post('ajax.php');
});
}
});
});
CSS:
/* show the move cursor as the user moves the mouse over the panel header.*/
#draggablePanelList .panel-heading {
cursor: move;
}
最后,HTML:
<div class="container">
<div class="row" id="draggablePanelList">
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading">You can drag this panel - 1.</div>
<div class="panel-body">Content ...</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading">You can drag this panel - 2.</div>
<div class="panel-body">Content ...</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading">You can drag this panel - 3.</div>
<div class="panel-body">Content ...</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading">You can drag this panel - 4.</div>
<div class="panel-body">Content ...</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading">You can drag this panel - 5.</div>
<div class="panel-body">Content ...</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading">You can drag this panel - 6.</div>
<div class="panel-body">Content ...</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading">You can drag this panel - 7.</div>
<div class="panel-body">Content ...</div>
</div>
</div>
</div>
</div>
它的拖放功能没有任何问题。问题是,我从数据库加载面板的顺序,我想在重新排序后将新的框顺序保存到数据库。
使用$ .post(&#39; ajax.php&#39;),我正在尝试向服务器发送值,但如何检测项目的新订单?
此外,如果您有任何建议可以使代码更加专业&#34;,请不要犹豫,向我提出您的建议。谢谢!