jquery UI datepicker关闭next()。focus() [英] Jquery UI datepicker closes on next().focus()

查看:121
本文介绍了jquery UI datepicker关闭next()。focus()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从datepicker小部件中随后选择两个日期,然后在第一个选择时,我想要关注第二个日期。
我这样设置:

 < input type =textclass =dateid = fromDatename =fromDate/> 
< input type =textclass =dateid =toDatename =toDate/>

$(input.date)。datepicker({
onSelect:function(){
$(this).next(。date)。 ;
}
});

但是当我选择第一个日期,第二个打开然后关闭窗口...为什么? p>

我看到onClose事件有效,但如果没有选择第一个日期,我不想打开另一个日期...



请尝试从小提琴: http://jsfiddle.net/Ld98p/1/

解决方案

这很有趣。即使调用datepicker小部件的 show()方法也会产生相同的行为。 / p>

看起来像在 onSelect 中的回调是在一个非常复杂的情况下被调用的,事件性的和触发的 focus 或强制 - 从回调本身显示弹出窗口不能依赖。



但是,触发

  $(input.date)。 datepicker({
onSelect:function(){
window.setTimeout($。proxy(function(){
$(this).next(。date)。
},this),10);
}
});

您可以在您更新的小提琴


I need to select subsequently two dates from a datepicker widget, then I want to focus on the second when the first one is selected. I set it up like this:

<input type="text" class="date" id="fromDate" name="fromDate"/>
<input type="text" class="date" id="toDate" name="toDate"/>

$("input.date").datepicker({
    onSelect: function(){
        $(this).next(".date").focus();
    }
});

But when I select the first date the second opens then closes the window... why?

I saw that with onClose event works, but I don't want to open the other date if the first one is not selected...

Please try it from fiddle: http://jsfiddle.net/Ld98p/1/

解决方案

That's interesting. Even calling the show() method of the datepicker widget results in the same behavior.

It looks like the onSelect callback is invoked in a pretty complex situation, events-wise, and triggering focus or force-showing the popup from the callback itself cannot be relied upon.

However, triggering focus from a slightly delayed function appears to work:

$("input.date").datepicker({
    onSelect: function() {
        window.setTimeout($.proxy(function() {
            $(this).next(".date").focus();
        }, this), 10);
    }
});

You can test it in your updated fiddle.

这篇关于jquery UI datepicker关闭next()。focus()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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