[英]Upload Form Data WIth Bootstrap Modals
我的网页上有一个包含表单的模式。 我已经设置了表单操作和所需的输入,如下所示:
<div class="modal fade" id="addCategory" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add Category</h4>
</div>
<div class="modal-body">
<form action="/add-category" method="post" enctype="multipart/form-data">
<div class="form-group">
<label>Title</label>
<input class="form-control" type="text" placeholder="Category Title"> <br>
<label>Upload Image</label>
<input class="form-control" type="file" accept="image/*" id="selImg" onchange="showImage.call(this)">
<img src="#" id="imgPreview" style="display: none; height: 100px; width: 100px">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save</button> // save details to form action endpoint, close modal and refresh the page
</div>
</div>
问题出在单击“保存”按钮时,这是引导程序模版附带的。 单击按钮后,我想提交刷新页面的表单。 我正在使用node backend
,如果我使用dom
来监听按钮上的事件点击,请向我解释。
我怎样才能做到这一点? 谢谢。
您需要确保<button type="submit" class="btn btn-primary">Save</button>
位于<form>
标记内,并且您已经准备就绪。 目前,它还没有提交表单并因此触发您想要的刷新。
另一个解决方案是利用Bootstrap Modal的事件:
$('#myModal').on('hidden.bs.modal', function () {
$('#myForm').trigger('submit')
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.