获取引导的DateTimePicker AJAX加载后工作加载、工作、DateTimePicker、AJAX

2023-09-11 01:30:33 作者:丘比特来射我

我有这个简单的脚本,工作正常的形式:

 <脚本>
        $(函数(){
            $('日期选择器。')的DateTimePicker({pickTime:假的,格式为:DD-MM-YYYY});
            $('。timepicker)的DateTimePicker({pickDate:假的,格式为:HH:MM,pick12HourFormat:假})。
        });

< / SCRIPT>
 

但是,如果我通过AJAX加载形式进入自举3模式 - 时间和日期选择器不工作。我知道这个问题是因为我加载通过AJAX的形式。

那么,如何注册功能的新加载的AJAX形式?

编辑:这是我如何调用Ajax模型:

 <一个数据切换=模式类=BTN BTN-危险的href =/例如数据目标=#myModal>加载模态< / a取代;
 

解决方案

将在你的模式示例页面的头标签的的jquery.js。 jQuery的,你可能会引用它的父页面上是不可见的,你都显示为模态的第二页。

前端插件BootStrap datetimepicker的使用

I have this simple script which works on a normal form:

<script>
        $(function () {
            $('.datepicker').datetimepicker({ pickTime: false, format: "DD-MM-YYYY" });
            $('.timepicker').datetimepicker({ pickDate: false, format: "HH:mm", pick12HourFormat: false });
        });

</script>

But if I load a form via ajax into a Bootstrap 3 modal - the time and date pickers dont work. I know the issue is because I am loading the form via ajax.

So how do I register the functions for the newly loaded ajax form?

Edit: this is how I am calling the ajax model:

<a data-toggle="modal" class="btn btn-danger" href="/example" data-target="#myModal">Load Modal</a>

解决方案

Place a jquery.js inside head tag of your modal example page. Jquery on the parent page where you might have referenced it is not visible to the second page which you are showing as modal.