【问题标题】:Determine if click event source comes from thead判断点击事件源是否来自thead
【发布时间】:2016-07-28 19:41:30
【问题描述】:

我已经有一段时间没有运气了,所以我想我会在 SO 上抛出一些东西。

只有当源来自tbody 而不是thead 时,我才需要执行单击事件的功能和Angular 指令。我尝试了多种途径来获取此信息,但我似乎无法正确使用语法。

任何帮助/指导将不胜感激。这是我最新/最好的尝试。会告诉你我要做什么:

/* Linker for the directive */
var linker = function (scope, elm, attrs) {  
    window.setTimeout(function(){
        elm.find('table tbody tr.uib-weeks td button span.text-info').closest('tr').find('button').addClass('chosenReportWeek');
    }, 1000); // This is a hack until we can find the proper load/render event           

    elm.on('click', function(event) {
        if(event.target.parent.indexOf('thead') === -1){
            elm.find('table tbody tr.uib-weeks button.active').closest('tr').find('button').addClass('chosenReportWeek');
        }                
    });
};

【问题讨论】:

标签: javascript angularjs angularjs-directive onclick dom-events


【解决方案1】:

正确的语法如下:

if($(event.target).closest('thead').length === 0)

【讨论】:

    猜你喜欢
    • 2014-05-23
    • 1970-01-01
    • 2013-03-11
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    相关资源
    最近更新 更多