如何在表mouseover中使用jQuery访问tr id甚至?

时间:2018-01-14 05:23:12

标签: jquery html html-table

我尝试了以下方法从表格行获取<TR> id,其中鼠标悬停在事件上,但是我得到了未定义的内容。请建议一种在下面的函数中获取id的方法。

以下需要修复,我的控制台出现 keyfromTable 会抛出undefined

  

的eval(JSON.stringify($( 'TR')ATTR( 'ID')));

$('table').on('mouseenter', 'tr', function() {
    var tr=$(this);
    setTimeout(function() {
        if (!insidePopover) {
             var keyfromTable = eval(JSON.stringify($('tr').attr('id')));
             console.log(keyfromTable);
                   $.getJSON( "http://localhost:8111/app/rest/builds/id:137/artifacts/content/additionalInfo.json", function(data) {
                    result = JSON.stringify(data);
                    var obj = JSON.parse(result);
                    var items = [];
                        for (var key in obj) { 
                            var keyfromJson = eval(key);

                    //console.log(" OUTSIDE IF " + keyfromJson + " " + keyfromTable + " ");
                            if (keyfromJson == keyfromTable) {
                            //items.push( "<li id='" + key + "'>" + obj[key]['Fi'] + "</li>" );
                            console.log("Inside IF " + keyfromJson + " " + keyfromTable + " ");

                            }
                        }
                    $('tr').attr('data-content', keyfromTable);
                    $(tr).popover('show');
                    attachEvents(tr);

            });
}
}, 20);
 });

0 个答案:

没有答案