position()和表 [英] position() and tables

查看:69
本文介绍了position()和表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这怎么可能不会提示0(相反,它会提示50)?

How can it be that this doesn't alert 0 (instead, it alerts 50)?

我需要相对于桌子的td位置

I need the td position relative to the table

http://jsfiddle.net/vxVCE/

HTML:

<div style="height:40px"></div>
<div>
    <table id="tbl">
        <tr>
            <td id="td1">linje 1</td>
        </tr>
        <tr>
            <td id="td2">linje 2</td>
        </tr>
    </table>
</div>

JS:

var elm = $('#td1');
var position = elm.position();
alert(position.top);

我需要相对于表格的tr位置:)

edit: I need the tr position relative to the table :)

推荐答案

position: relative;添加到表中.这样做会使其警报为0.否则,它将相对于文档找到位置.

Add position: relative; to the table. Doing that will make it alert 0. Otherwise, it's finding position relative to the document.

这篇关于position()和表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆