簡體   English   中英

使用自舉程序上載表格數據

[英]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">&times;</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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM