Boostrap 模态在使用 jquery 连接时不加载
Boostrap modal not loading when wired using jquery
我有以下链接,我正在尝试在单击引导模式时加载引导模式,但 javascript 函数似乎没有触发。而不是在模态内加载视图,而是将其加载为新页面?
<a href="/Reports/ReportSummary" class="icon-before js-report-summary" data-icon="'uf080"> </a>
@*this is the modal definition*@
<div class="modal hide fade in" id="report-summary">
<div id="report-summary-container"></div>
</div>
<script >
$('a.js-report-summary').click(function (e) {
var url = $(this).attr('href'); // the url to the controller
e.preventDefault();
$.get(url, function (data) {
$('#report-summary-container').html(data);
$('#report-summary').modal('show');
});
});
</script>
public ActionResult ReportSummary()
{
// some actions
return PartialView("ReportSummary", viewmodel)
}
// Report summary view which contains modal
<div class="modal-dialog" role="document">
<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>
<h4 class="modal-title" id="myModalLabel">@ViewBag.FormName - Analysis</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">
Close</button>
</div>
</div>
</div>
控制台中也没有显示错误,那么为什么 jquery 函数没有触发呢?
在您的点击函数中,添加参数e
这将代表event
然后在函数本身中添加e.preventDefault()
这将停止刷新效果。
在您的
控制器方法上尝试
public ViewResult ReportSummary()
{
// some actions
if(Request.IsAjaxRequest())
return PartialView("ReportSummary", viewmodel);
else
return View("ReportSummary", viewmodel);
}
在您的视野中
$('#exampleModal').on('show.bs.modal', function (event) {//give your model wrapper an id
//do some ajax and get html
$.ajax({
url:'',
success:function(data){
$('#report-summary-container').html(data);
}
});
})
在锚标记上,添加data-toggle="modal" data-target="#exampleModal"
如果您不想使用引导事件触发您的模式
$('#myModal').modal('show')
相关文章:
- 使用优化器在慢速连接上加载main.js时需要js超时
- 动态加载fancybox并将其连接
- socket.io”;“连接”;刷新/重新加载时的事件不会激发
- Jquery 移动错误消息,当没有互联网连接加载谷歌地图
- Jquery移动检查时没有互联网连接显示错误消息,而不是加载谷歌地图
- 在异步加载谷歌地图时处理网络断开连接
- Strobhe.js和Openfire在页面重新加载时终止连接
- 连接/拼接 Web 图像资源以缩短加载时间
- 加载资源时出现 OpenTok JS 连接超时问题
- 加载脚本文件以测试在线连接是否有任何缺点
- 使用 grunt requirejs 与单个大型缩小文件连接缓慢时加载问题
- 检查连接是否有网址 - 图像加载
- 科尔多瓦 - 首先检查互联网连接,然后加载正文页面
- 如何通过https连接使用google.load加载谷歌库
- https连接中加载的Http内容
- 加载和连接js/jsx文件
- 对于连接速度较慢的用户来说,加载图像显示得太晚
- Node.js/Sockets-用户连接,它加载以前的消息,但它将消息加载到所有其他聊天用户,而不是刚刚连接的用户
- 网页暂时关闭/未加载(由于连接太多?)
- AngularJS“连接后端”应用程序没有在编辑对话框上加载数据-使用最新的firebase