如何使用JavaScript找出单元格的大小 [英] How can i find out the size of a cell with javascript

查看:68
本文介绍了如何使用JavaScript找出单元格的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个弹出窗口,在<th>的正下方弹出,因此看起来像<td>(不要问为什么).在1024 * 760上,其宽度与表格标题单元格相同,但在1280上,宽度则不如表头单元格.如何编写脚本以找出<th>的宽度? (我正在使用jQuery.)

I have a popup that pops up right underneathe a <th> so it looks like the <td> (don't ask why). on 1024 *760 its the same width as the table header cell, but on 1280 it's not as wide. How can i wirte a script to find out the width of my <th>? (I'm using jQuery.)

<th id="telephoneTH" width="25%" >
<span  id="telephoneSpan" class="headerShortDetails">Telephone</span><span onclick="showContactPopup();"  class="infoSpans"> ${bean.phoneNumber}</span>
</th>


var width2 = $('#telephoneTH').outerWidth();
alert(width2);

错误:"null"为null或不是对象

error: 'null' is null or not an object

推荐答案

使用jQuery,您可以使用$('td').outerWidth();.您可能需要向TD元素添加一个类,以便使用jQuery选择器进行指定.顺便说一下,此jQuery方法使用了嵌入"到JS的outsideWidth属性,但jQuery更容易:)

With jQuery, you could use $('td').outerWidth(); You would likely need to add a class to the TD element in order to specify it with your jQuery selector. By the way, this jQuery method uses the outerWidth property "baked in" to JS, but jQuery is easier :)

这篇关于如何使用JavaScript找出单元格的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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