Я хочу вызвать тот же эффект, что и при нажатии клавиши табуляции на элементе, который имеет фокус.Есть ли способ сделать это?Я пытаюсь переместить фокус на следующий элемент.
Спасибо!
(опция jQuery)
Примерно так (с помощью jQuery):
<!DOCTYPE html> <html lang="en"> <head> <title>LOL Focus!</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script> </head> <form> <input class="focusable" type="text" value="lol"/> <input class="focusable" type="text" value="lol" /> <input class="focusable" type="text" value="lol" /> <input class="focusable" type="text" value="lol" /> <input class="focusable" type="text" value="lol" /> <input class="focusable" type="text" value="lol" /> </form> <input type="button" id="trigger_button" value="lol" /> <script type="text/javascript"> $(function() { var focusable = $('.focusable'), last_element_index = focusable.length - 1, current_index; focusable.each(function(i) { $(this).click(function() { current_index = i; }) }); $('#trigger_button').click(function() { current_index = (should_reset_current_index()) ? 0 : current_index + 1; focusable[current_index].focus(); }); function should_reset_current_index() { return (typeof(current_index) === 'undefined') || (current_index == last_element_index) } }); </script> </html>
Нужно было эмулировать функциональность вкладки некоторое время назад, и теперь я выпустил ее как библиотеку , которая использует jquery .
EmulateTab : плагин jQuery для эмуляции вкладок между элементами на странице.
Вы можете посмотреть, как это работает в демоверсии .
if (myTextHasBeenFilledWithText) { // Tab to the next input after #my-text-input $("#my-text-input").emulateTab(); }