jQuery Accordion Focus

僤鯓⒐⒋嵵緔 提交于 2020-01-13 19:26:06

问题


This is my first post so let me know if you would like more information!

I am using a select list and a jQuery accordion. When the user selects a value from the list it opens up the relevant part of the accordion using the activate method.

This works fine apart from it also focusses the window on the accordion rather than leaving the user on in the same place.

Does anyone know how to prevent this?


回答1:


You may be able to store the currently active element, and restore focus after the user clicks on the accordion header.

You can retrieve the currently focused element using the following code:

function onElementFocused(e)
{
    if (e && e.target)
        document.activeElement =
        e.target == document ? null : e.target;
} 

if (document.addEventListener)
    document.addEventListener("focus", onElementFocused, true); 

This will keep the currently focused element in the document.activeElement variable.

Using the 'changestart' and/or 'change event with the accordion, you can then restore the focus to the desired element every time the accordion changes.

You may need to add a clause or two to prevent the accordion header divs being set as the current active element in the above code, otherwise you'll just restore focus to the accordion header.

The above code is untested, as is the idea, but it should work I believe.



来源:https://stackoverflow.com/questions/2584906/jquery-accordion-focus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!