简体   繁体   中英

Jquery UI calendar in ajax loaded dialog

I have link with onclick="open_dialog" which opens jquery ui dialog. It loads its content with ajax and that content loads another content test2.php with ajax that has input tag with class="calendar". Problem is that, if i click on input it won't show any calendar. Maybe somebody knows why?

function open_dialog() {
    var url = 'test.php'; 
    var dialog;
    if ($('#test').length) {
        dialog = $('#test');
    } else {
        dialog = $('<div id="test" class="type_' + type + '" style="display:hidden;"></div>').appendTo('body');
    }
    dialog.load(
        url, 
        {},
        function (responseText, textStatus, XMLHttpRequest) {
            dialog.dialog({
                open: function(event, ui) {
                    $('.calendar').datepicker();
                }
            });
        }
    );
    return false;
}

Sorry, but i found the answer: I had to call calendar in second ajax call like this:

$('#content_in_test_dialog').load(
    'test2.php', 
    function(response, status, xhr) {
        $('.calendar').datepicker();
    }
);

At first you should to find the problem? 1) first add alert('first line of open_dialog function'); and check is call or not. 2) second check that is calendar added self html content to html page. May be it added self content, but some css style hide it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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