AJAX加载的内容中未定义引导程序日期选择器

bootstrap-datepicker undefined in AJAX loaded content

本文关键字:未定义 引导程序 日期 选择器 加载 AJAX      更新时间:2023-09-26

我正在使用此repo中的引导程序日期选择器:https://github.com/eternicode/bootstrap-datepicker主页:http://eternicode.github.io/bootstrap-datepicker

它适用于带有日期字段的表单。然而,在该表单上,我还有一个按钮,可以以模式打开子表单,该子表单也有日期字段。问题是,在该子窗体上,日期选择器是未定义的,因此不起作用。

在使用AJAX加载的模态表单页面中,我有以下片段:

<script type="text/javascript">
$(document).ajaxComplete(function()
{
    var thing = $('.date-container input');
    console.log(thing);        //prints as a valid element
    console.log($.datepicker); //prints as 'undefined'
    thing.datepicker({         //crashes the script due to .datepicker being undefined
        autoclose: true,
        todayHighlight: true
    });
});
</script>

我甚至试着从文档中运行这段代码来设置模式脚本中的格式,但这段代码也导致了一个错误,称日期选择器未定义:

$.fn.datepicker.defaults.format = "mm/dd/yyyy";

因此,出于某种原因,在通过AJAX加载的模态中包含的脚本中,日期选择器只是未定义的,但在加载模态的父页面中,日期选取器工作正常。

有什么问题吗?

是否在模态页面中再次加载jQuery?我怀疑这可能是罪魁祸首。