问题描述
我正在填写表格.因此,我在所有字段中都设置了javascript验证.我希望仅当用户单击提交"按钮
I am making a form. So in that i have set javascript validation for all the fields. I want the modal to pop-up only if the form is valid when the user clicks the submit button
请仅使用js建议答案.我对jquery也不太熟悉.请不要让我将验证更改为jquery(因为上次我问有关验证的问题时,有人告诉我要更改它).我试图将onsubmit添加到<form>
,但是它不起作用
Pls suggest answers only using js. I not very familiar with jquery as well.Pls don't ask me to change my validation to jquery(because last time when i had asked a question about validation people told me to change it). I have tried to add onsubmit to <form>
but it doesn't work
我的模态
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
我的按钮和验证码
<div class="row container">
<div class="col-sm-4"><label>Text<input class="form-control" type="text" required>
</label>
</div>
<div class="col-sm-4"><label>Text<input class="form-control" type="text" required>
</label></div>
<div class="col-sm-4"><label>Text<input class="form-control" type="text" required>
</label></div>
</div>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button></form>
但是正如您所看到的,当我按下按钮时,模态弹出.但是我希望它在提交时弹出.我什至尝试使用<form onsubmit>
But as you can see the modal pops up when i press the button. But i want it to pop-up onsubmit. I even tried using <form onsubmit>
推荐答案
JS
function myfn() {
$('#myModal').modal('show');
}
HTML
<form onsubmit="event.preventDefault(); myfn()">
//all inputs and other info
</form>
这篇关于如何在提交表单时显示引导程序模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!