Jquery ui datepicker in loaded ajax page

I have a problem, I am loading a page in a div with a form that has a date. I want to get datepicker, but when the page loads with ajax, jquery does not see my input. I tried something like this:

$('#birthdate').live('click', function() {
    $(this).datepicker({showOn:'focus'}).focus();
});

Well, it worked, but the entire datapicker blinks, sometimes it doesn’t show, etc. Is there a chance that a bad show datepicker is from my own onlcik function? sort of:

function choosedate() {
    $('#birhtdate').datepicker();
}

its not only with datepicker, I just don't know how to use jquery inside the loaded ajax page.

+3
source share
3 answers

You should be able to call $("#yourdate").datepicker()ajax when processing your response.

For example:

$.get("new_div_contents.whatever", function(data) { 
  // do your thing with the data
  $("#yourdate").datepicker();
});
+8
source

.

  • ,
  • .

, AJAX, , . , () DOM datepicker. , datepicker . .

$.get('/url/to/action', function(data) {
    $('#birthdate').datepicker( { showOn: 'focus' } );
     var bd = $('#birthdate').focus().get(0);
     if (bd) bd.focus();
});

, jQuery , focus() jQuery . , javascript-. , () .

0

zindex is an option

$('.datepicker').datepicker({'zindex':1200});
0
source

Source: https://habr.com/ru/post/1715277/


All Articles