我想补充row (div)
,然后用拖放的方式,jQuery的添加button
到row
UI这样的:(jsfiddle)添加可拖动元素的jQuery UI动态的div
HTML
<div class="rowDashboard">Row</div>
<div class="buttonDashboard">Button</div>
<div id="content"></div>
脚本
var rowIndex = 0;
var buttonIndex = 0;
$(init);
function init() {
$('.rowDashboard').draggable({
containment: '#content',
cursor: 'move',
helper: addNewRow,
revert: "invalid",
});
$('#content').droppable({
accept: ".rowDashboard",
drop: function (ev, ui) {
ui.helper.attr('style', '');
$(ui.helper).addClass('rowDraggable');
ui.helper.clone().appendTo('#content');
},
});
//------ sortable rows --------------
$("#content").sortable({
cancel: ".fixed"
});
$("#content").disableSelection();
// ----------------------------------
//------- buttonDraggable -----------
$('.buttonDashboard').draggable({
containment: '#content',
cursor: 'move',
helper: addNewButton,
});
// ----------------------------------
$('.rowDraggable').droppable({
accept: ".buttonDashboard",
drop: function (ev, ui) {
ui.helper.attr('style', '');
$(ui.helper).addClass('buttonDraggable');
ui.helper.clone().appendTo($(this));
},
});
}
function addNewButton() {
buttonIndex++;
return '<input type=\'button\' value=\'button ' + buttonIndex + ' \'> </input>';
}
function addNewRow() {
rowIndex++;
return '<div> Row ' + rowIndex + ' </div>';
}
但我不知道为什么button
不会被添加到row
。
如果有人能够解释这个问题的解决方案,这将是非常有益的。
您可以检查此琴https://jsfiddle.net/4u8dcL5p/4/ –