我通过鼠标悬停来检索 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>
最佳答案
next
方法用于检索下一个同级,因此您可以使用 children
或 find
方法以及 :first
选择器或 first
方法:
$(document).on('mouseover','tr[role="row"]',function(){
var VId = $(this).children('[role="gridcell"]:first').attr('title');
$('#TestPanelA').html(VId);
});
关于jQuery 使用 NEXT 并检索标题属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17145961/