问题描述
我在我的输入内使用datepicker,我的最后一个字段是datepicker输入,验证后我想将焦点设置在我的表单中的另一个输入,但问题是datepicker不关闭,甚至没有关闭它没有焦点..当我将焦点设置在另一个输入字段时,如何关闭datepicker?
(我尝试过.datepicker(hide);但是没有为我工作)。
更新:
这是我的代码:
$(function()
{$(#test_date).datepicker ({
dateFormat:dd / mm / yy
});
})
//当我调用我的函数:
$(#test_date).datepicker(hide); // --->这不行!
感谢先进。
问题编辑使用最新版本的jqueryUI
JqueryUi会在元素丢失时自动关闭datepicker关注用户交互,但不要用JS更改焦点时。
您正在调用的功能是从分配了datepicker的输入中删除焦点,您还需要调用: / p>
$(#test_date〜.ui-datepicker)hide();
此代码隐藏了#test_date的兄弟(〜)的datepicker。
I'm using datepicker inside my input , my last field is the datepicker input , after validating it i want to set focus on another input inside my form , but the problem is the datepicker is not closed even taht it does not have the focus..
how can I close the datepicker when i set the focus on another input field?(I tried .datepicker("hide"); but it did not worked for me).
UPDATE:this is my code:
$(function()
{ $( "#test_date" ).datepicker({
dateFormat: "dd/mm/yy"
});
});
//when i call my function:
$( "#test_date" ).datepicker("hide"); //---> this does not work!
Thank's In Advance.
Question Edited to work with the latest version of jqueryUI
JqueryUi auto-closes the datepicker when an element loses focus by user interaction, but not when changing focus with JS.
Where you are calling your function which removes focus from the input assigned a datepicker you also need to call:
$("#test_date ~ .ui-datepicker").hide();
This code is hiding the datepicker which is a sibling (~) of #test_date.
这篇关于jquery关闭datepicker输入失去焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!