简体   繁体   中英

how can i focus to the new element …By pressing the Tabbutton

How Can I focus to the new Element pressing the TAB

 var objClass = obj.className;
        $(obj).datepicker({
            changeMonth:true,
            changeYear:true,
            onClose:function()
            {

              $("#ui-datepicker-div").css("visibility", "hidden");
              focusToNextField();         
            }

Use .attr("tabIndex", "-1")

$('#dateelement').datepicker({
    changeMonth: true,
  changeYear: true,

}).next('button.ui-datepicker-trigger')
      .attr("tabIndex", "-1");

Here is the demo

Observe the cursor moves to the next textbox on hittin TAB button

您可以使用$('#nextElem").focus();

Use $(":focusable") to get current element and add focus on next element

var objClass = obj.className;
$(obj).datepicker({
    changeMonth: true,
    changeYear: true,
    onClose:function() {
        $("#ui-datepicker-div").css("visibility", "hidden");
        var focusables = $(":focusable");   
        var current = focusables.index(this),
        next = focusables.eq(current+1).length ? focusables.eq(current+1) : focusables.eq(0);
        next.focus();
    }

});

I suppose you need to have a keydown event:

$(obj).datepicker({
    changeMonth: true,
    changeYear: true,
    onClose:function() {
        $("#ui-datepicker-div").css("visibility", "hidden");
        // focusToNextField();       
    }
}).on('keydown', function(e){
   e.preventDefault();
   if(e.which === 9){
     $(this).next(':input').focus();
   }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM