我有一個包含窗體的Bootstrap模態。模態還包含提交和取消按鈕。現在按照我的要求,對提交按鈕點擊模態的,形式是成功提交,但語氣沒有得到closed..Here是我的HTML ..關閉Bootstrap模態在表單提交
<div class="modal fade" id="StudentModal" tabindex="-1" role="dialog" aria-labelledby="StudentModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<form action="~/GetStudent" class="form-horizontal" role="form" method="post" id="frmStudent">
<div class="modal-footer">
<div class="pull-right">
<button type="submit" class="btn btn-success"><i class="glyphicon glyphicon-ok"></i> Save</button>
<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> Close</button>
</div>
</div>
</form>
</div>
</div>
怎麼辦呢..Please幫助我..謝謝..
這幾乎是正確的,但不**從事件處理函數返回false,因爲這與調用相同事件對象上的preventDefault()和stopPropagation()。調用preventDefault()可以阻止發生的提交,這不是所期望的結果。這也是爲什麼data-dismiss attrib不起作用 - 引導模式js添加的事件也會在事件上調用preventDefault()。 – othp
#按鈕應該是表單的ID,而不是按鈕(請參閱[鏈接](https://developer.mozilla.org/en-US/docs/Web/Events/submit)頂部的註釋)如果在按鈕上使用事件,請使用click事件。 – othp
也考慮調用'.modal('hide');'而不是'切換',否則如果您的表單也可以在沒有可見模式的情況下提交,那麼當提交事件被觸發時將顯示模式。 – othp