开发者

Jquery UI live(): Focusing on events other than 'click'

The following code shows Jquery UI Date Picker upon click of a (initially hidden) textbox. Anyone know how to allow the 'tab' button to activate it as well? The datepicker class in this case applies to a textbox. Many users would use tab instead of clicking, and it doesn't work right now..

$(function() { 
  开发者_Python百科  $('.datepicker').live('click', function () {
            $(this).datepicker({showOn: 'both'}).focus();
    });
});


When you say "allow the 'tab' button to activate", I assume you mean hitting tab to shift focus into the text box? If that's the case, the live handler works on the focus event too, so you could just change your code to catch the focus event instead of click (click will cause the field to get focus & fire then too).

Edit: ..oops, re-reading the code, my hasty example would cause an infinite focus loop, try this instead:

$(function() { 
    $('#ReferenceNumber').live('focus', function () {
        var picker = $(this).datepicker({showOn: ''});
        picker.datepicker("show");
    });
});


you probably want to delegate on keydown.

$('body').live('keydown',function(e){
        //Keycode 9 is the tab key
        if(e.keyCode == 9) {
            $('.datepicker').datepicker({showOn: 'both'}).focus();
        }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜