在线求救,能否得到表格中单元格的列号?

micker 2004-04-24 05:32:58
能否得到表格中单元格的列号(第机列)? 行号可以得到,但是得到列号不能用类似的方法得到,请问如何得到列号.
谢谢!
...全文
52 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
myhyli 2004-04-26
  • 打赏
  • 举报
回复
<table border=1 onclick="alert(getColsLength(this))">
<tr>
<td colspan=2>12</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
<script>
function getColsLength(tbObj){
var count=tbObj.rows[0].cells.length;
for(var i=0;i<tbObj.rows[0].cells.length;i++){
count+=parseInt(tbObj.rows[0].cells[i].colSpan,10)-1;
}
return count;
}
</script>
micker 2004-04-25
  • 打赏
  • 举报
回复
非常感谢!
我现在只需要总列数,有没有很简单的实现方法?
谢谢!
wanghr100 2004-04-25
  • 打赏
  • 举报
回复
<table border>
<tr><td>Click and look statusBar</td><td>Click and look statusBar</td><td>Click and look statusBar</td></tr>
<tr><td>Click and look statusBar</td><td>Click and look statusBar</td><td>Click and look statusBar</td></tr>
<tr><td>Click and look statusBar</td><td>Click and look statusBar</td><td>Click and look statusBar</td></tr>
<tr><td>Click and look statusBar</td><td>Click and look statusBar</td><td>Click and look statusBar</td></tr>
<tr><td>Click and look statusBar</td><td>Click and look statusBar</td><td>Click and look statusBar</td></tr>
</table>
<script>
function document.onclick(){
var e=window.event.srcElement
if(e.tagName=="TD"){
window.status="第"+(e.parentElement.rowIndex+1)+"行,第"+(e.cellIndex+1)+"列"
}
}
</script>
micker 2004-04-25
  • 打赏
  • 举报
回复
谢谢!
列总数能直接得到吗?
还是要通过the_table.cells.length和the_table.rows.length来计算?
好象是不能用the_table.cols.length.
谢谢!
wanghr100 2004-04-25
  • 打赏
  • 举报
回复
obj.focus()获得焦点时,文本框中的内容不会被选中,请问如何处理后才能让它被选中
-----------------

<input type="text" onfocus="this.select()" value="灰豆宝宝.net">
micker 2004-04-25
  • 打赏
  • 举报
回复
谢谢各位!
在请问大家一下,为什么用,obj.focus()获得焦点时,文本框中的内容不会被选中,请问如何处理后才能让它被选中。
谢谢!
gaofaq 2004-04-25
  • 打赏
  • 举报
回复
<table border=1 onclick="alert(this.rows[0].cells.length)">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
micker 2004-04-25
  • 打赏
  • 举报
回复
up
duwucna 2004-04-24
  • 打赏
  • 举报
回复
obj.rowIndex是行号
obj.cellIndex是列号
gaofaq 2004-04-24
  • 打赏
  • 举报
回复
不好意思
写错了


<TABLE id=tbl cellSpacing=1 cellPadding=1 border=1>
<TBODY>
<TR>
<TD width=100>This is Line1</TD></TR>
<TR>
<TD width=100>This is Line2</TD></TR>
<TR>
<TD width=100 onclick="alert(this.cellIndex)">This is Line3</TD></TR>
</TBODY>
</TABLE>
gaofaq 2004-04-24
  • 打赏
  • 举报
回复
<TABLE id=tbl cellSpacing=1 cellPadding=1 border=1>
<TBODY>
<TR>
<TD width=100>This is Line1</TD></TR>
<TR>
<TD width=100>This is Line2</TD></TR>
<TR>
<TD width=100 onclick="alert(this.parentElement.cellIndex)">This is Line3</TD></TR>
</TBODY>
</TABLE>

87,902

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧