Bootstrap 没有出现对话框
Posted
技术标签:
【中文标题】Bootstrap 没有出现对话框【英文标题】:Dialog box not appearing Bootstrap 【发布时间】:2018-12-12 14:19:35 【问题描述】:我正在尝试提交表单并在提交表单后提醒用户。我正在使用 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");
);
);
我按照此处发布的 anwser 找到了执行此操作的代码:
How to display an Alert in Bootstrap Modal
【问题讨论】:
【参考方案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>
【讨论】:
【参考方案2】:试试这个
<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");
);
);
【讨论】:
以上是关于Bootstrap 没有出现对话框的主要内容,如果未能解决你的问题,请参考以下文章
Bootstrap(和 jquery)、webpack、rails - 没有完全集成
Azure App Service .net6 部署 - 错误:EISDIR:对目录进行非法操作,打开“/home/site/wwwroot/wwwroot/Identity/lib/bootstra