开发者

Change the focus on jQueryUI Datepicker on close

开发者 https://www.devze.com 2023-03-28 09:43 出处:网络
I want jQueryUI to change the focus to another element after the picker is closed: $( \"#datepicker\" ).datepicker({

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

精彩评论

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