我正在嘗試構建UI拖放構建器。到目前爲止,我的問題是,當我添加和行或複製行時,我不允許在新添加的行內添加列。我如何解決這個問題,以允許重複或附加的行,然後在該行內添加列?構建UI拖放構建器
$('.add_or_delete button').click(function() {
if ($(this).text() == 'Add Row') {
$(this).parent().parent().append('<div class="row"><div class="col"></div><div class="add_or_delete"><button>Add Column</button><button>Delete Column</button></div></div>');
make_DragDrop();
}
if ($(this).text() == 'Add Column') {
$(this).parent().parent().append('<div class="col"></div>');
make_DragDrop();
}
});
function make_DragDrop() {
$(".row, #columns").sortable({
placeholder: "ui-state-highlight",
forcePlaceholderSize: true,
connectWith: ".connectedSortable",
});
$(".row").disableSelection();
}
make_DragDrop();
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div class="builder_container">
<div class="element_picker">
<div class="select_layouts">
<ul class="connectedSortable" id="columns">
<li class="col">1</li>
<li class="col">2</li>
<li class="col">3</li>
<li class="col">4</li>
</ul>
</div>
</div>
<div class="builder_canvas">
<div class="canvas_container">
<div class="section">
<div class="add_or_delete">
<button>Add Row</button>
<button>Delete Row</button>
</div>
<div class="row connectedSortable">
<div class="add_or_delete">
<button>Add Column</button>
<button>Delete Column</button>
</div>
<div class="col">1</div>
<div class="col">2</div>
</div>
</div>
</div>
</div>
</div>
https://jsfiddle.net/mohamedyousef1980/ho307wme/你需要[事件綁定動態創建的元素?](https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements ) –
事件綁定和我到目前爲止的功能有什麼區別?@ Mohamed-Yousef –