jQuery - Set datepicker's container to a specific div

会有一股神秘感。 提交于 2020-01-02 03:53:05

问题


I'm using jQuery UI datepicker on an div. the div hides and shows by moving mouse. as the datepicker are exist at the end of the <body> tag, not inside my div, the div disappears when I move the mouse to the datepicker.

I loaded the datepicker like this:

Javascript

$("#dt1").datepicker({
    dateFormat: "dd/mm/yy",
    showOn: "button",
    buttomText: "Arrival date",
    buttonImage: "<button location>",
    buttonImageOnly: true,
});

HTML

<input type="text" id="dt1" size="10" name="dt1" value="Arrival Date" />

How can I set the container of the datepicker to a specific div?

Edit: See it on JSFiddle: http://jsfiddle.net/G4NzC/


回答1:


The solution is to move the dataPicker's div to inside the hidden-absolute-positioned-div.

something like this (this is just the idea by @andrew but you need to improve css styling and other things):

Note that #dt1 is the input text for the date, #ui-datepicker-div is the datepicker's div and #bookingBox is the hidden-absolute-positioned-div.

$("#dt1").datepicker({ 
dateFormat: "dd/mm/yy", 
showOn: "button", 
buttomText: "Arrival date",
buttonImage: "http://www.inbar.co.il/designFiles/Inbar_Ico_Calander.png", 
buttonImageOnly: true,
beforeShow:function(textbox, instance){
    $('#ui-datepicker-div').css({
        position: 'absolute',
        top:-20,
        left:5                   
    });
    $('#bookingBox').append($('#ui-datepicker-div'));
    $('#ui-datepicker-div').hide();
} });



回答2:


Simplest solution which I've found is

$("#myDatePicker").datepicker({
   beforeShow:function(textbox, instance){
     $('.DivToAppendPicker').append($('#ui-datepicker-div'));
   }
});


来源:https://stackoverflow.com/questions/23721957/jquery-set-datepickers-container-to-a-specific-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!