Tabindex based on enter key by getting form elemens not working in Jquery

前端 未结 2 521
自闭症患者
自闭症患者 2021-01-17 01:45

I have a form, and I am able to get all form elements through serializeArray(). I want to focus() on form elements based on their tabindex value us

2条回答
  •  攒了一身酷
    2021-01-17 02:08

    You can also try this HTML



    This input is hidden


    SCRIPT ///////////

    $(document).on("keypress", ".TabOnEnter" , function(e)
      {
        //Only do something when the user presses enter
        if( e.keyCode ==  13 )
        {
           var nextElement = $('[tabindex="' + (this.tabIndex+1)  + '"]');
           console.log( this , nextElement ); 
           if(nextElement.length )
             nextElement.focus()
           else
             $('[tabindex="1"]').focus();  
        }   
      });
    
    //Hidden inputs should get their tabindex fixed, not in scope ;)
    //$(function(){ $('input[tabindex="4"]').fadeOut();  })
    

    ////////////// Worked Fine in EI,Chrome, Mozilla . not tested in safari and other browser

提交回复
热议问题