我正在使用一个名为 Flatpickr 的插件。它工作正常,但是当我添加点击行为并尝试将其附加到另一个 div 时,它会在那里显示多个文本框。很奇怪,现在我现在需要做什么,我应该在那个 div 中找到 flatpicr,然后如果它有更多,则将其删除。或对此有任何其他替代解决方案。
<form id="taskForm">
<div class="container">
<div class="row" style="margin-top:15px;">
<div class="panel panel-default">
<div class="panel-body">
<div class="taskContent">
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label>Date Range<sup class="text-danger">*</sup></label>
<div class="input-group">
<input type="text" class="form-control flatpickr" placeholder="Select Date">
<div class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</div>
</div>
</div>
</div>
</div>
<hr>
</div>
<div id="taskEmpty">
</div>
<div class="row">
<div class="col-lg-1 pull-right text-right">
<h1 class="glyphicon glyphicon-plus-sign" id="addTask" style="color:#32c24d;cursor:pointer;"></h1>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary btn-submit">Create</button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
这是脚本
flatpickr(".flatpickr", {
enableTime: true,
altInput: true,
altFormat: "j- M- Y h:i K",
"mode": "range"
});
$("#addTask").on("click", function(event) {
event.stopPropagation();
var clone = $(".taskContent").clone();
$("#taskEmpty").html(clone);
//initialize date again
flatpickr(".flatpickr", {
enableTime: true,
altInput: true,
altFormat: "j- M- Y h:i K",
"mode": "range"
});
});
这是小提琴
提前致谢