使用新的Twitter Bootstrap版本:Bootstrap 4 alpha,我无法使Modal在远程模式下工作.它在Bootstrap 3上运行良好。在bootstrap 4下,我正在弹出窗口,但是没有加载模型主体.没有电话到
myRemoteURL.do
加载模型主体。
代码:
<button type="button" data-toggle="modal" data-remote="myRemoteURL.do" data-target="#myModel">Open Model</button>
<!-- Model -->
<div class="modal fade" id="myModel" tabindex="-1"
role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h3 class="modal-title" id="myModalLabel">Model Title</h3>
</div>
<div class="modal-body">
<p>
<img alt="loading" src="resources/img/ajax-loader.gif">
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
最新回答
- 2021-1-111 #
- 2021-1-112 #
根据官方文档,我们可以执行以下操作(https://getbootstrap.com/docs/4.1/components/modal):
$('#exampleModal').on('show.bs.modal', function (event) { var button = $(event.relatedTarget) // Button that triggered the modal var recipient = button.data('whatever') // Extract info from data-* attributes // If necessary, you could initiate an AJAX request here (and then do the updating in a callback). // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead. var modal = $(this) modal.find('.modal-title').text('New message to ' + recipient) modal.find('.modal-body input').val(recipient) })
所以,我认为这是最好的方法:
$('#modal_frame').on('show.bs.modal', function (e) { $(this).find('.modal-content').load(e.relatedTarget.href); });
Adapt to your needs
- 2021-1-113 #
正如其他答案和Bootstrap文档所指出的那样, Bootstrap 4 需要处理
show.bs.modal
事件,以将内容加载到模式中.可用于从HTML字符串或远程URL加载内容.这是 working example ...$('#theModal').on('show.bs.modal', function (e) { var button = $(e.relatedTarget); var modal = $(this); // load content from HTML string //modal.find('.modal-body').html("Nice modal body baby..."); // or, load content from value of data-remote url modal.find('.modal-body').load(button.data("remote")); });
Bootstrap 4远程URL演示
另一种选择是一旦从Ajax调用返回数据,就打开模态。
$.ajax({ url: "http://someapiurl", dataType: 'json', success: function(res) { // get the ajax response data var data = res.body; // update modal content $('.modal-body').text(data.someval); // show modal $('#myModal').modal('show'); }, error:function(request, status, error) { console.log("ajax call went wrong:" + request.responseText); } });
Ajax演示中的Bootstrap 4加载模式
- 2021-1-114 #
在Asp.NET MVC中,这对我有用
html
<a href="#" onclick="Edit(1)">Edit item</a> <div class="modal" id="modalPartialView" />
jquery
<script type="text/javascript"> function Edit(id) { $.ajax({ url: "@Url.Action("ActionName","ControllerName")", type: 'GET', cache: false, data: {id: id}, }).done(function(result){ $('#modalPartialView').html(result) $('#modalPartialView').modal('show') //part of bootstrap.min.js }); } <script>
Action
public PartialViewResult ActionName(int id) { // var model = ... return PartialView("_Modal", model); }
- 2021-1-115 #
如果使用Jquery slim版本(如所有Bootstrap 4文档和示例中一样),则加载功能将失败
您需要使用完整版的Jquery
相关问题
- javascript:从另一个页面获取Bootstrap的模式内容javascriptjqueryhtmltwitterbootstrapmodaldialog2021-01-11 22:55
- css:如何获得一个固定位置的div,以使其与内容水平滚动? 使用jQueryjquerycssfixed2021-01-11 16:26
- css:Bootstrap 3-连续使用超过12列csstwitterbootstraptwitterbootstrap32021-01-11 03:28
- javascript:焦点在IE中不起作用javascriptjqueryhtmlcss2021-01-10 23:29
- Twitter Bootstrap CSS影响Google Mapsgooglemapstwitterbootstrapcss2021-01-10 02:55
发现了问题:他们在引导程序4中删除了远程选项
我使用JQuery来实现此已删除的功能。