我让mouseover工作以检索ID。但是尝试使用next()来检索标题attr(title =“01”)但由于某种原因它不起作用。我不确定我在这里缺少什么。
JS:
$(document).on('mouseover','tr[role="row"]',function(){
var VId = $(this).next('[role="gridcell"]').attr('title');
$('#TestPanelA').html(VId);
});
PHP(此表由jqGrid生成):
<tr role="row" id="1" tabindex="-1" class="jqgrow ui-row-ltr H0">
<td role="gridcell" style="text-align: left; height: 16px;" title="01" aria-describedby="0Li_A">01</td>
<td role="gridcell" style="text-align: right; height: 16px;" title="822" aria-describedby="0Li_C">822</td>
</tr>
答案 0 :(得分:3)
next
方法用于检索下一个兄弟,因此您可以将children
或find
方法与:first
选择器或first
方法一起使用:
$(document).on('mouseover','tr[role="row"]',function(){
var VId = $(this).children('[role="gridcell"]:first').attr('title');
$('#TestPanelA').html(VId);
});
答案 1 :(得分:1)
next()
用于兄弟元素,你想要一个孩子,你可以使用children()
:
$(document).on('mouseover','tr[role="row"]',function(){
var VId = $(this).children('[role="gridcell"]').first().attr('title');
$('#TestPanelA').html(VId);
});
答案 2 :(得分:0)
试试这个:
var VId = $(this).children('[role="gridcell"]').attr('title');
在事件处理程序中,$(this)引用tr而不是td。所以你需要通过chilren查找。
我希望它有所帮助。