如何获取表格行的右上角(x,y)坐标

时间:2012-12-08 22:05:32

标签: jquery

表格行示例:

<tr class="row"><td>Blah</td><td>Blah 2</td></tr>

如何离开这里:

$('row').click(function(){

});

所以当点击行的td单元格时,如果给出行的右上角的(x,y)坐标?

1 个答案:

答案 0 :(得分:4)

您可能正在寻找offset()position(),具体取决于相对距离:

$('row').click(function(){
    $(this).offset(); //returns an object with top and left values relative to the document
    //or
    $(this).position(); //returns an object with top and left values relative to the parent
});

通常像这样使用(两种方法都相同):

 $('row').click(function(){
     var left = $(this).offset().left + $(this).width(),
          top = $(this).offset().top;
});