Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

html - If TAB is pressed can it be triggered as shift + TAB (JQuery, JS)

I have a HTML List with radio buttons as bullet points. Inside the first list element there is a text Input. The focus is on the Text input.
If I TAB to the next element, even if I set tabindexes it skips the <li> and focuses the next elements after the </ul>. If I press Shift TAB the focus goes to the previouse <li> element. (Actually I think this is good behavior.)

But I have this one customer who can't press shift+TAB.

Is there a way to manipulate / simulate a key press that it is triggered as Shift keypress?
Is there maybe a pure HTML solution?

<ul>
<li><input type='radio'><input type='text'>this input field has focus</li>
<li><input type='radio'>...</li>
</ul>

I tried some Javascript and JQuery trickery but no luck.

$(document).keydown(function (e) {
    if (e.keyCode == 9)
    {
        e.preventDefault();
        e = jQuery.Event('keypress');
        e.which = 9;
        e.shiftKey = true;
        $('input').trigger(e);
    }
});

Does not work in my case. As well as:

var evt = document.createEvent('KeyboardEvent');
evt.initKeyEvent('keypress',true, true, window, false, false,false, true, 0, e.keyCode 9);
this.dispatchEvent(evt);
question from:https://stackoverflow.com/questions/66061844/if-tab-is-pressed-can-it-be-triggered-as-shift-tab-jquery-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Actually it was a problem with the TAB indexes. So removing all tabindexes, then setting new tabindexes solved everything.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...