引导模式中的引导日期拾取器,使页面空白并添加年份
Bootstrap datepicker in bootstrap modal, making page blank and adds year
我有一个引导模态,并通过web2py ajax在该模态内加载的表单。我的日期picker字段是在这种形式,它不激活,因为它是通过ajax加载。因此,我添加了一个侦听器来捕获加载的ajax,然后激活日期拾取器。然后,当我单击该字段时,它打开日期选择器,但随后将整个页面内容替换为年份?下面是一个GIF截图:
GIF联系编辑:
按照Sam的要求,下面是一些帮助诊断问题的代码:
/**
* JS
*/
// Fill modal with content from link href
$("#myModal").on("show.bs.modal", function (e) {
var link = $(e.relatedTarget);
// this line loads the form via ajax
$.web2py.component(link.attr("href"),'modal-body');
// this listens for ajax and activates bootstrap datepicker after
$(document).ajaxComplete(function(e, xhr, settings) {
if (settings.url == link.attr("href")) {
$("#myModal").find('input.date').datepicker(
);
}
});
});
/**
* HTML
*/
<div class="modal fade" id="myModal" 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>
<h4 class="modal-title" id="myModalLabel">Edit Deal</h4>
</div>
<div id="modal-body" class="modal-body"></div>
</div>
</div>
</div>
这个错误也在控制台中被调用,但不确定这是否会特别影响日期拾取器,希望它有帮助:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
您可以为日期选择器添加z-index
.datepicker{
z-index:2000;
}
失败的原因是datepicker会触发触发我们用来加载模态内容的侦听器的show
事件。因为它是模态的,所以它会使用错误的URL并加载仪表板页面,这会导致失败,因为它是AJAX调用。
相关文章:
- 如何自动添加target=“_空白“;仅限于外部链接
- 如何添加target=“_空白“;万一
- 如何使用jquery在html表的右侧添加一定数量的空白列
- 如何将空白选项添加到木偶收藏视图生成的选择中
- 添加目标=“_空白“;到锚点标签
- 在传单图层组中为空白图块图层添加选项
- 当我添加javascript时,它会显示一个空白页
- 添加换行符 JavaScript pdf 表单时的文本字段空白
- 在打印 html 内容中添加外部样式表引用后,打印预览为空白
- 如何将空白/空行添加到绑定到MemoryStore的EnhancedGrid中
- Php和javascript数组-跳过空白值并添加到新数组中
- 如何添加target=“_空白“;到JavaScript window.location
- Firefox不会“;正确地“;打开具有目标=“0”的链接_空白“;JavaScript在页面加载时添加的属性
- 将目标空白添加到JavaScript生成的链接中
- 当添加“;目标“:"空白“;通过javascript链接,打开的选项卡是“;回收的“;(重复使用)-以任何方式
- Angular Kendo Dropdownlist自动添加空白选项
- 如何在javascript中添加空白
- 添加空白函数时出现Javascript函数错误
- 正则表达式的新手.在所有结束标记后添加空白
- 空白添加对话框