admin管理员组文章数量:1418657
My project has a datepicker which has buttons to go previous/next months. it looks like this:
but when i click the buttons on right and left corner of the control, it suddenly disappears.
jquery function:
$( "#departDate" ).datepicker({
showOtherMonths: true,
//inline:true,
dateFormat: 'dd-mm-yy',
numberOfMonths: 2,
selectOtherMonths: true,
minDate: 0,
onClose: function (selectedDate) {
$("#arriveDate").datepicker("option", "minDate", selectedDate);
if (!single && $("#arriveDate").val()=="")
$("#arriveDate").focus();
}
});
i tried to ment out onClose:
and minDate
but none of these fixed problem.
When i remove blur function on this datepicker, it stops disappearing. But i need to make it disappear when click anywhere out of this tool.
My project has a datepicker which has buttons to go previous/next months. it looks like this:
but when i click the buttons on right and left corner of the control, it suddenly disappears.
jquery function:
$( "#departDate" ).datepicker({
showOtherMonths: true,
//inline:true,
dateFormat: 'dd-mm-yy',
numberOfMonths: 2,
selectOtherMonths: true,
minDate: 0,
onClose: function (selectedDate) {
$("#arriveDate").datepicker("option", "minDate", selectedDate);
if (!single && $("#arriveDate").val()=="")
$("#arriveDate").focus();
}
});
i tried to ment out onClose:
and minDate
but none of these fixed problem.
When i remove blur function on this datepicker, it stops disappearing. But i need to make it disappear when click anywhere out of this tool.
Share Improve this question edited Mar 11, 2014 at 14:32 AloneInTheDark asked Sep 4, 2013 at 7:04 AloneInTheDarkAloneInTheDark 9385 gold badges15 silver badges39 bronze badges 1- can you share it in a fiddle? – Praveen Commented Sep 4, 2013 at 7:19
3 Answers
Reset to default 2you should add a click event an check for all elements in your datepicker. this might be useful for you:
$(document).on("click", function (e) {
var elem = $(e.target);
if (!elem.hasClass("hasDatepicker") &&
!elem.hasClass("ui-datepicker") &&
!elem.hasClass("ui-icon") &&
!elem.hasClass("ui-datepicker-next") &&
!elem.hasClass("ui-datepicker-prev") &&
!$(elem).parents(".ui-datepicker").length) {
$('#departDate').datepicker('hide');
}
I think you are using two js files where your next button will override so try to change sequence of js file on your html page
I don't find this problem persist in my fiddle.
Since you mentioned,
When i remove blur function on this datepicker, it stops disappearing. But i need to make it disappear when click anywhere out of this tool?
I have a workaround solution like whenever you click outside the datepicker, it will be hidden.
$(document).on('click',function (e) {
var container = $("#departDate");
if (!container.is(e.target)
&& container.has(e.target).length === 0) {
container.hide();
}
});
Check this working in JSFiddle
Hope you can understand.
本文标签: javascriptjQuery DatePicker disappears when i click NextPrevious buttonsStack Overflow
版权声明:本文标题:javascript - jQuery DatePicker disappears when i click NextPrevious buttons - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745295540a2652054.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论