我在一个名为的页面中有一个锚点,但在menu.html获取Bootstrap模式以显示另一个名为的页面中的数据时遇到了麻烦Lab6.html。
menu.html
Lab6.html
<div class="collapse navbar-collapse navbar-exl-collapse"> <ul class="nav navbar-nav" id="menu"> <li><a href="/emplookup.html">Lookup</a></li> <li><a href="/modalexample.html">Modals</a></li> <li><a href="/Lab6.html#theModal" data-toggle="modal">Lab 6</a></li><!-- this one --> </ul> </div>
<div class="modal fade text-center" id="theModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">X</button> <h1>Lab 6</h1> </div> <div class="modal-body"> <div class="panel panel-default"> <div class="panel-heading text-center"> Employee Information </div> <div class="panel-body"> <div class="row"> <div class="text-right col-xs-2">Title:</div> <div class="text-left col-xs-3" id="title"></div> <div class="text-right col-xs-2">First:</div> <div class="text-left col-xs-3" id="firstname"></div> </div> <div class="row"> <div class="text-right col-xs-2">Phone#</div> <div class="text-left col-xs-3" id="phone"></div> <div class="text-right col-xs-2">Email</div> <div class="text-left col-xs-3" id="email"></div> </div> <div class="row"> <div class="text-right col-xs-2">Dept:</div> <div class="text-left col-xs-3" id="departmentname"></div> <div class="text-left col-xs-2">Surname:</div> <div class="text-left col-xs-4"> <input type="text" placeholder="enter last name" id="TextBoxLastName" class="form-control" /> </div> </div> </div> </div> <div class="modal-footer"> <div class="panel-footer"> <input type="button" value="Find Employee" id="empbutton" /> <div class="col-xs-10" id="lblstatus"></div> </div> </div> </div> </div> </div> </div> <script src="Scripts/jquery-2.1.4.min.js"></script> <script src="Scripts/bootstrap.min.js"></script>
我做错什么了吗?
您尝试从另一个页面获取模式内容的方式不正确。
根据Bootstrap的文档:
如果提供了远程URL,则将通过jQuery的load方法加载一次内容并将其注入.modal-contentdiv中。如果您使用的是data- api,则可以选择使用href属性指定远程源。一个示例如下所示: <a data-toggle="modal" href="remote.html" data-target="#modal">Click me
如果提供了远程URL,则将通过jQuery的load方法加载一次内容并将其注入.modal-contentdiv中。如果您使用的是data- api,则可以选择使用href属性指定远程源。一个示例如下所示:
.modal-content
<a data-toggle="modal" href="remote.html" data-target="#modal">Click
me
因此,首先,您应该将menu.html文件更改为类似于上面的代码:
<li><a href="Lab6.html" data-target="#theModal" data-toggle="modal">Lab 6</a></li>
然后,Lab6.html页面的一部分必须位于menu.html页面内部。例如:
<div class="modal fade text-center" id="theModal"> <div class="modal-dialog"> <div class="modal-content"> </div> </div> </div>
最后,您LAB6.html将只有里面的代码.modal-content。例如:
LAB6.html
<div class="modal-header"> <button type="button" class="close" data-dismiss="modal">X</button> <h1>Lab 6</h1> </div> <div class="modal-body"> <div class="panel panel-default"> <div class="panel-heading text-center"> Employee Information </div> <div class="panel-body"> <div class="row"> <div class="text-right col-xs-2">Title:</div> <div class="text-left col-xs-3" id="title"></div> <div class="text-right col-xs-2">First:</div> <div class="text-left col-xs-3" id="firstname"></div> </div> <div class="row"> <div class="text-right col-xs-2">Phone#</div> <div class="text-left col-xs-3" id="phone"></div> <div class="text-right col-xs-2">Email</div> <div class="text-left col-xs-3" id="email"></div> </div> <div class="row"> <div class="text-right col-xs-2">Dept:</div> <div class="text-left col-xs-3" id="departmentname"></div> <div class="text-left col-xs-2">Surname:</div> <div class="text-left col-xs-4"> <input type="text" placeholder="enter last name" id="TextBoxLastName" class="form-control" /> </div> </div> </div> </div> <div class="modal-footer"> <div class="panel-footer"> <input type="button" value="Find Employee" id="empbutton" /> <div class="col-xs-10" id="lblstatus"></div> </div> </div> </div>