jQuery 使用 NEXT 并检索标题属性

标签 jquery jquery-ui

我通过鼠标悬停来检索 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 方法用于检索下一个同级,因此您可以使用 childrenfind 方法以及 :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/

相关文章:

javascript - 哪些 jQuery 插件应该合并到 jQuery 或 jQueryUI 中

javascript - 带 jquery 的全屏图像 slider

javascript - slider 在 jQuery 选项卡中不起作用

jquery-ui - 使用 AngularJS 和表单验证禁用 jQuery 按钮

javascript - 将#hash 标记更改为在页面加载时链接

javascript - 如何从属性中获取数据然后相应地禁用按钮

javascript - 如何使用其数据计算所有可见 div 的总和,如果 div 变为隐藏,也会重新计算

javascript - 滚动事件在移动设备上不起作用

javascript - 为什么 jQuery 幻灯片在选择时弹跳?

jquery ui 可拖动约束 ina 轴 x 和给定坐标