这是我的.cshtml页面代码,我使用jquery中继器是在这个代码中继器工作很好,但我想在这个中继器中添加一些修改,但我被困在这里。你可以看到我的密码。
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data", @class = "repeater" }))
{
<div data-repeater-list="">
<div data-repeater-item="">
<div class="col-lg-12 col-md-12 col-sm-12">
<input type="file" name="Docfiles" />
</div>
</div>
</div>
<input data-repeater-create type="button" value="Add" />
<button>Save</button>
}
@section Scripts{
<!-- Import repeater js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.repeater/1.2.1/jquery.repeater.js"></script>
<script>
$(document).ready(function () {
$('.repeater').repeater({
// (Optional)
// start with an empty list of repeaters. Set your first (and only)
// "data-repeater-item" with style="display:none;" and pass the
// following configuration flag
initEmpty: true,
// (Optional)
// "show" is called just after an item is added. The item is hidden
// at this point. If a show callback is not given the item will
// have $(this).show() called on it.
show: function () {
$(this).slideDown();
},
// (Optional)
// "hide" is called when a user clicks on a data-repeater-delete
// element. The item is still visible. "hide" is passed a function
// as its first argument which will properly remove the item.
// "hide" allows for a confirmation step, to send a delete request
// to the server, etc. If a hide callback is not given the item
// will be deleted.
hide: function (deleteElement) {
if (confirm('Are you sure you want to delete this element?')) {
$(this).slideUp(deleteElement);
}
},
// (Optional)
// Removes the delete button from the first list item,
// defaults to false.
isFirstItemUndeletable: true
})
});
</script>
}我想在这个格式中改变html,如下图所示。

发布于 2020-09-17 03:18:04
首先,名称格式是在jquery.repeater.js中设置的,如果您想要更改它,需要更改jquery.repeater.js,下面是一个演示:
1.将jquery.repeater.js添加到项目中。
我将js复制到我的项目中如下所示:

2.在jquery中找到setIndexes并像这样更改var newName = groupName + '[' + index + '][' + name + ']' +(您也可以将它更改为您想要的其他格式):

3.将脚本src从cdnjs更改为您自己的项目:
<script src="~/lib/jquery-repeater/jquery.repeater.js"></script>4.结果:

https://stackoverflow.com/questions/63924939
复制相似问题