jQuery focusout事件不会触发table元素 [英] jQuery focusout event doesn't trigger on table element

查看:92
本文介绍了jQuery focusout事件不会触发table元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使表支持多行选择(目前只有CTRL +鼠标点击组合)。一切正常,但当我在表区域外单击时,行不会取消选择。不幸的是,我发现聚焦事件根本不会触发。这是我的代码:

I'm trying to make a table support multiple row selection (for the moment just the CTRL + mouseclick combination). Everything works fine, but when I click outside the table area, the rows don't deselect. Unfortunately, I have found out that the focusout event doesn't trigger at all. Here's my code:

    $(".library tbody tr").live('click', function (event) {
        event.preventDefault();

        if (event.ctrlKey) {
            $(this).toggleClass('selected-row');
        } else {
            $(".library tbody tr").removeClass("selected-row");
            $(this).addClass("selected-row");
        }
    });

    $("table.library").live('click', function () {
        $(".library").addClass("focused");
    });

    $("table.library").live('focusout', function () {
        $(this).removeClass("focused");
    });

还有其他人处理过这个问题吗?提前谢谢!

Has anyone else dealt with this issue? Thank you in advance!

推荐答案

'focusout'事件仅在焦点离开可以的元素时触发首先要集中注意力,比如输入元素。据我所知,table元素无法获得焦点。你需要以其他方式处理所选行的取消选择,Lollero在他对你的问题的评论中提出了一个可能的解决方案。

The 'focusout' event only fires when focus leaves elements which can be focused in the first place, such as input elements. A table element can't get that focus, as far as I know. You'd need to handle the deselection of selected rows in some other way, Lollero mentoned one possible solution in his comment on your question.

这篇关于jQuery focusout事件不会触发table元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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