如何使用 JQuery 获取 在表中的位置?
例如:
<table>
<tr><td>1,1</td><td>2,1</td></tr>
<tr><td>2,1</td><td>2,2</td></tr>
</table>
我想使用以下功能:
$("td").click(function(){
alert(xxxx)
})
得到<td> 单击时的位置,但是如何呢?
The index 不带参数调用的函数将获得相对于其兄弟姐妹的位置(无需遍历层次结构)。
$('td').click(function(){
var $this = $(this);
var col = $this.index();
var row = $this.closest('tr').index();
alert( [col,row].join(',') );
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)
|