focus on next tabindex of HTML element onEnter keypress by JQuery

后端 未结 6 1677
日久生厌
日久生厌 2020-12-05 11:06

Hi Friends, I\'m working on a small task which is to enable the user to tabindex the html element upon enter keypress.

As im new to jquery , I have

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 11:44

    I found a couple of minor jQuery issues. Fixed here: JSFiddle.

    This line:

    $('*').attr('tabindex', tabindex).focus();
    

    can be written like this:

    $('[tabindex=' + tabindex + ']').focus();
    

    and this:

    $('#Msg').text($(this).id + " tabindex: " + tabindex 
               + " next element: " + $('*').attr('tabindex').id);
    

    is not calling the id attribute the jQuery way (you are using JavaScript syntax, but the result of $(this) is a jQuery object. So... $(this).id becomes $(this).attr('id').

    The form still has a submission problem, that I didn't dig too far into, but it changes focus and fills out the '#Msg' element now.

提交回复
热议问题