jquery在输入失去焦点时关闭日期选择器 [英] jquery close datepicker when input lose focus

查看:41
本文介绍了jquery在输入失去焦点时关闭日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的输入中使用 datepicker,我的最后一个字段是 datepicker 输入,在验证它之后我想将焦点设置在我的表单中的另一个输入上,但问题是 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..

当我将焦点设置在另一个输入字段上时,如何关闭日期选择器?(我试过 .datepicker("hide"); 但它对我不起作用).

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).

更新:这是我的代码:

$(function()
    {    $( "#test_date" ).datepicker({
                dateFormat: "dd/mm/yy"
        });
        });
 //when i call my function:
 $( "#test_date" ).datepicker("hide"); //---> this does not work!

提前致谢.

推荐答案

问题已编辑以使用最新版本的 jqueryUI

Question Edited to work with the latest version of jqueryUI

当元素因用户交互而失去焦点时,JqueryUi 会自动关闭日期选择器,但在使用 JS 更改焦点时不会.

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();

此代码隐藏了日期选择器,它是#test_date 的兄弟 (~).

This code is hiding the datepicker which is a sibling (~) of #test_date.

这篇关于jquery在输入失去焦点时关闭日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆