我正在使用https://github.com/DubFriend/jquery.repeater (jquery repeater) 来克隆表单字段。它成功地克隆了该字段,但是,当提交表单时,该字段没有被发送。
所以,到目前为止,我发现data-repeater-item正在发送之外的输入字段。
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.repeater/1.2.1/jquery.repeater.min.js"></script>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
print_r($_POST);
}
?>
<h2>Repeater</h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" class="repeater" method="POST" enctype="multipart/form-data">
<input type="text" name="full_name">
<div data-repeater-list>
<div data-repeater-item>
<input type="text" name="text-input" value="A"/>
<select name="select-input">
<option value="A" selected>A</option>
<option value="B">B</option>
</select>
<input data-repeater-delete type="button" value="Delete"/>
</div>
</div>
<input data-repeater-create type="button" value="Add"/>
<button type="submit">Submit</button>
</form>
<script>
$(document).ready(function () {
'use strict';
$('.repeater').repeater({
show: function () {
$(this).slideDown();
},
hide: function (deleteElement) {
if(confirm('Are you …Run Code Online (Sandbox Code Playgroud) 我正在使用Select2和jQuery表单转发器(https://github.com/DubFriend/jquery.repeater)
我已经在google /上搜索了2天,但似乎无法让它工作.
include jquery/select2.js/jquery.repeater.js
var form = $('#form');
form.find('select').select2();
form.repeater({
show: function () {
$(this).show(function(){
form.find('select').select2('destroy').select2();
});
},
hide: function (remove) {
$(this).hide(remove);
}
});
Run Code Online (Sandbox Code Playgroud)
问题是jQuery.repeater克隆了div标签,其中input2已经初始化并且已经更改了DOM,因此jQuery.repeater会复制更改的DOM.我试图在调用重复动作之前销毁select2,但是dindt也可以工作.