简体   繁体   English

Bootstrap Datepicker无法与AJAX load()一起使用

[英]Bootstrap datepicker not working with AJAX load()

I have an AJAX loaded page - users.php . 我有一个加载的AJAX页面users.php Every time I click on the users tab, the following function is called: 每次单击“用户”选项卡时,都会调用以下功能:

function users(){
    var id = document.getElementById("usersstab");
    $("#users").load("load.php");
    $("#users").load("users.php");
}

In users.php, I have a form that is hidden. 在users.php中,我有一个隐藏的表单。 The form is displayed only on the click of "Add user" button. 该表格仅在单击“添加用户”按钮时显示。 In that form, I have a birth date field, for which I want to use the datepicker() . 在这种形式下,我有一个出生日期字段,我想使用datepicker()

<input id="dobofsubuser" type="text" name="subuserdob" class="form-control" />

I call this function at the footer of the main (parent page) : 我在主页(父页面)的页脚处调用此函数:

$('#dobofsubuser').datepicker({
    format: "yyyy-mm-dd",
    endDate: "Current Date",
    startView: 2
});

This doesn't show the calendar and I have tried to look for answers but none of the previously mentioned solutions have helped this far. 这没有显示日历,我已经尝试寻找答案,但是到目前为止,前面提到的解决方案都没有帮助。 Can someone please tell me what I am doing wrong or what needs to be done so that the datepicker works on load() ? 有人可以告诉我我做错了什么或需要做什么才能使datepicker在load() Thanks in advance! 提前致谢!

This is the order of my scripts: 这是我的脚本的顺序:

        <script src="js/modernizr-2.6.2.min.js"></script>
        <script src="http://code.jquery.com/jquery.js"></script>
        <script src="js/bootstrap.min.js"></script> 
        <script src="js/validetta.min.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script src="js/jquery.mask.min.js"></script>
        <script src="js/sweet-alert.min.js"></script>
        <script src="js/bootstrap-datepicker.min.js"></script>
        <script type="text/javascript" src="http://js.stripe.com/v2/"></script>

If there is no solution here, can someone please suggest an alternative calendar plugin that would work well with ajax loaded pages? 如果这里没有解决方案,请问有人可以推荐一个替代日历插件,该插件可以很好地加载ajax页面吗?

Try to init your datepicker after load : 尝试在加载后初始化datepicker

$("#users").load("users.php", function() {
    $('#dobofsubuser').datepicker({
        format: "yyyy-mm-dd",
        endDate: "Current Date",
        startView: 2
    });
});

Hope this helps. 希望这可以帮助。

Possibly there is some js library that is interfering with your code. 可能有一些js库正在干扰您的代码。

Try this for bootstrap datepicker 试试这个引导日期选择器

$(document).ready(function () {
    var datepicker = $.fn.datepicker.noConflict();
    $.fn.bootstrapDP = datepicker;  
    $("#datepicker").bootstrapDP({  format: 'yyyy-mm-dd'});  
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM