我正在尝试提交表单,并在表单提交后提醒用户。我正在使用Bootswatch的引导主题Cosmo。当我提交表单时,尖叫声变暗,好像对话框正在出现,但对话框从未出现。 HTML如下:
<div class="content">
<div id="infoContactMe" class="info">
<form action="contactMe.php" method="POST" id="contactForm">
<fieldset>
<legend>Contact Me</legend>
<div class="form-group">
<label for="exampleInputEmail1">Email Address</label>
<input type="email" class="form-control" id="contactEmail1" name="contactEmail1" aria-describedby="emailHelp" placeholder="Enter email">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label class="col-form-label" for="inputDefault">Name</label>
<input type="text" class="form-control" placeholder="Enter Name" id="contactName" name="contactName">
</div>
<div class="form-group">
<label for="exampleSelect1">Catagory</label>
<select class="form-control" id="contactCatagory" name="contactCatagory">
<option id="defulat">--Select Catagory--</option>
<option id="1">General Enquiry</option>
<option id="2">View Private Project</option>
<option id="3">Reference Contact</option>
</select>
</div>
<div class="form-group">
<label for="exampleTextarea">Query</label>
<textarea class="form-control" id="contactQuery" name="contactQuery" rows="5"></textarea>
</div>
<button type="button" class="btn btn-primary" id="contact">Submit</button>
</fieldset>
<!--Dialog Box-->
<div class="modal">
<div class="modal-dialog" role="document" id="contactDiaglog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p id="confirmation">Modal body text goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
我已经编写了一个基本的JQuery脚本来显示对话框。最终还将提交表单。
$(document).ready(function(){
$('#contact').click(function(){
$("#confirmation").html("You Clicked on Click here Button");
$('#contactDiaglog').modal("show");
});
});
我发现了遵循此处张贴的答案的代码:
答案 0 :(得分:1)
您需要在模态html中将id="contactDiaglog"
与<div class="modal">
一起使用,如下所示
$(document).ready(function(){
$('#contact').click(function(){
$("#confirmation").html("You Clicked on Click here Button");
$('#contactDiaglog').modal("show");
});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="content">
<div id="infoContactMe" class="info">
<form action="contactMe.php" method="POST" id="contactForm">
<fieldset>
<legend>Contact Me</legend>
<div class="form-group">
<label for="exampleInputEmail1">Email Address</label>
<input type="email" class="form-control" id="contactEmail1" name="contactEmail1" aria-describedby="emailHelp" placeholder="Enter email">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label class="col-form-label" for="inputDefault">Name</label>
<input type="text" class="form-control" placeholder="Enter Name" id="contactName" name="contactName">
</div>
<div class="form-group">
<label for="exampleSelect1">Catagory</label>
<select class="form-control" id="contactCatagory" name="contactCatagory">
<option id="defulat">--Select Catagory--</option>
<option id="1">General Enquiry</option>
<option id="2">View Private Project</option>
<option id="3">Reference Contact</option>
</select>
</div>
<div class="form-group">
<label for="exampleTextarea">Query</label>
<textarea class="form-control" id="contactQuery" name="contactQuery" rows="5"></textarea>
</div>
<button type="button" class="btn btn-primary" id="contact">Submit</button>
</fieldset>
<!--Dialog Box-->
<div class="modal" id="contactDiaglog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p id="confirmation">Modal body text goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
答案 1 :(得分:1)
尝试
<div class="content">
<div id="infoContactMe" class="info">
<form action="contactMe.php" method="POST" id="contactForm">
<fieldset>
<legend>Contact Me</legend>
<div class="form-group">
<label for="exampleInputEmail1">Email Address</label>
<input type="email" class="form-control" id="contactEmail1" name="contactEmail1" aria-describedby="emailHelp" placeholder="Enter email">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label class="col-form-label" for="inputDefault">Name</label>
<input type="text" class="form-control" placeholder="Enter Name" id="contactName" name="contactName">
</div>
<div class="form-group">
<label for="exampleSelect1">Catagory</label>
<select class="form-control" id="contactCatagory" name="contactCatagory">
<option id="defulat">--Select Catagory--</option>
<option id="1">General Enquiry</option>
<option id="2">View Private Project</option>
<option id="3">Reference Contact</option>
</select>
</div>
<div class="form-group">
<label for="exampleTextarea">Query</label>
<textarea class="form-control" id="contactQuery" name="contactQuery" rows="5"></textarea>
</div>
<button type="button" class="btn btn-primary" id="contact">Submit</button>
</fieldset>
<!--Dialog Box-->
<div class="modal" id="contactDiaglog" >
<div class="modal-dialog" id="contactDiaglog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p id="confirmation">Modal body text goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
jQuery
$(document).ready(function(){
$('#contact').click(function(){
$("#confirmation").html("You Clicked on Click here Button");
$('#contactDiaglog').modal("show");
});
});