如何获取索引 - 表格行 - 当我点击工具提示菜单模板中的li项目时 [英] How to get the index - table row -, when I click on li item in tooltip menu template

查看:106
本文介绍了如何获取索引 - 表格行 - 当我点击工具提示菜单模板中的li项目时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我正在使用的代码。在我的表中,在悬停销售列时,我有一个菜单模板工具提示,其中有3个列表项。当点击这些li项目中的一个时,我想知道销售列所在的表格行/索引。
以下代码:

Below is the code I am using. In my table, on hovering the sales column, I have a menu template tooltip that has 3 list items. When clicking on one of these li items, I want to know the table row/ index the sales column is in. Code below:

<td>
    <a href='#' class = 'sales_tooltip' data-templatename='Conifer' 
        data-title='<div class = "tooltip-menu">
                    <ul><li class="sales_rep"><a href="#">Sales Rep 1</a></li>
                    <li class="sales_rep"><a href="#">Sales Rep 2</a></li>
                    <li class="last-child sales_rep"><a href="#">Sales Rep 3</a></li>

                    </ul>
                    </div>'> 
        <i class = 'fa fa-male ' aria-hidden='true'></i>    
    </a>
</td>

我想要该行的tr索引,它的li项目工具提示是我点击的。 $('body')。on('click','.tooltip-menu li。
javascript code

I want the tr index of the row, whose li item tooltip I clicked on. javascript code

$('body').on('click', '.tooltip-menu li.sales_rep', function() {

    if(confirm("Have you chosen your sales rep?")){
        var sales_rep = $(this).find("a").html();

        //var $index = $(this).closest('a').closest('tr').index();
        var $index = $('#'+ $(this).data('for')).closest('tr').index();
    }

我试过这个,但这不起作用,因为它返回-1。
请帮忙

I tried this but this is not working, as it returns -1. Please help

推荐答案

如果您使用的是jQuery UI中的Tooltip,根据我的经验,实际的tooltip div是作为工具提示触发器元素的兄弟生成的,而非孩子。意味着您的工具提示菜单正在生成为您的锚的同级( a ),例如当您调用 .closest('a'),它不会返回任何东西,因为工具提示没有与该选择相匹配的父项r。

If you are using Tooltip from jQuery UI, from my experience, the actual tooltip div is generated as a sibling, not a child, of the tooltip trigger element. That means that your tooltip menu is being generated as a sibling of your anchor (a), such that when you call .closest('a'), it will not return anything since the tooltip has no parents that match that selector.

尝试 var index = $(this).closest('tr')。index();

这篇关于如何获取索引 - 表格行 - 当我点击工具提示菜单模板中的li项目时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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