Запретить получение фокуса определенными элементамиJquery

Программирование на jquery
Ответить
Гость
 Запретить получение фокуса определенными элементами

Сообщение Гость »


Итак, у меня есть следующая функция. Он прослушивает событие фокуса для всех элементов. Если этот элемент находится либо в

Код: Выделить всё

$mobileMenu
or

Код: Выделить всё

$menuItems
it permits it otherwise it removes the focus:

Код: Выделить всё

var $body = $("body");
var $mobileMenu = $("#mobile-menu");
var $menuItems = $("#main-menu a");

$body.on("focus.spf", "*", function(e){
e.stopPropagation();
$this = $(this);

// Prevent items from recieving focus and switching view
if (!$this.is($mobileMenu) && !$this.is($menuItems)) {
$this.blur();
} else {
console.log(this);
}
})
The issue I have is that this prevents the user from focusing on anything whatsoever if a normally focusable element that is now non-focusable precedes any of my white-listed elements as it just attempts to refocus on the same element over and over again.

Does anyone know how I can tell it to instead skip to the next focusable element?


Источник: https://stackoverflow.com/questions/209 ... ving-focus
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Jquery»