jQuery手风琴焦点 [英] jQuery Accordion Focus

查看:66
本文介绍了jQuery手风琴焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一篇文章,因此,如果您需要更多信息,请告诉我!

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

我正在使用选择列表和jQuery手风琴.当用户从列表中选择一个值时,它会使用Activate方法打开手风琴的相关部分.

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.

有人知道如何预防吗?

推荐答案

您也许可以存储当前活动的元素,并在用户单击手风琴标题后恢复焦点.

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); 

这会将当前关注的元素保留在document.activeElement变量中.

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

使用手风琴的'changestart'和/或'change事件,您可以在每次手风琴更改时将焦点恢复到所需的元素.

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.

您可能需要添加一两个子句,以防止将手风琴头div设置为上述代码中的当前活动元素,否则,您只需将焦点恢复到手风琴头即可.

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.

这篇关于jQuery手风琴焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆