取得表格中的某一行的值

<table id="mytbl">
....
</table>
<script language="javascript">
/*
mytbl.rows //这个表格的所有行的集合
mytbl.rows[0] //这个表格的第一行
mytbl.rows[0].cells //这个表格第一行的所有单元格集合
mytbl.rows[0].cells[0] //这个表格第一行的第一个单元格
mytbl.rows[0].cells[0].innerText //这个表格第一行的第一个单元格里的文字(可读写)
mytbl.rows[0].cells[0].innerHTML //这个表格第一行的第一个单元格里的HTML代码(可读写)
*/
</script>


<table>
<tr id='1'>
<td>1</td>
<td>2</td>
</tr>
</table>
<script>
alert(document.getElementById('1').cells[0].innerText)
alert(document.getElementById('1').cells[1].innerText)
</script>
**********************************************************
以下是我在项目中做过的:
<script type="text/javascript">
var flag=-1; //表格行标识符
var curRow=null;
function SelectRow(TrObj){
if(curRow) curRow.style.backgroundColor="#FFFFFF";
TrObj.style.backgroundColor="#FFCC00";
curRow=TrObj;
if(flag!=TrObj.rowIndex){
flag=TrObj.rowIndex;
var corpNo=curRow.cells[0].innerText;
alert(curRow.cells[0].innerText+"----获取第一列的值----");
submit3(corpNo);
} else{

}
}
function submit3(corpNo){
alert(flag+"----进入到submit3()中----");
store_set.findcompanyById(corpNo,cominfodata); //dwr操作

}
</script>
.....
<s:iterator value="#request.findallcompany">
<tr onClick="SelectRow(this)">
<td height="30" class="top_underline"><div align="center"><s:property value="corpNo"/></div></td>
<td height="30" class="top_underline" ><div align="center"><s:property value="corpName"/></div></td>
<td height="30" class="top_underline" ><div align="center"><s:property value="corpIsshort"/></div></td>
<td height="30" class="top_underline" ><div align="center"><s:property value="corpAddress"/></div></td>
<td height="30" class="top_underline" ><div align="center"><s:property value="corpPostno"/></div></td>
<td height="30" class="top_underline" ><div align="center"><s:property value="corpPhone"/></div></td>
</tr>
</s:iterator>
****************************************************
[b][color=red]curRow.rows[0].cells[0].children[0].value
rows[i] 表示取某一行的值;
cells[i] 表示取某一列的值;
children[i] 表示取某一列中第几个文本框的值,(或者下拉框,复选框。。。)[/color] [/b] :D
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值