开发者

Change the focus on jQueryUI Datepicker on close

I want jQueryUI to change the focus to another element after the picker is closed:

$( "#datepicker" ).datepicker({
    onClose: function(dateText, inst) { 
        $("#time").focus();              //doesn't work
    $("#time").addClass('debug');    //works
}
});

The above should work but unfortunately datepicker seems to have a command inst开发者_C百科.input.focus(); (I think) called after the onClose callback which resets the focus to the original input element. I'm wondering if there is way round this with bind().


You can have some delay and execute it if the plugin is setting the focus after onClose callback.

$( "#datepicker" ).datepicker({
    onClose: function(dateText, inst) { 
      setTimeout(function(){
        $("#time").focus();
      }, 200);
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜