62,041
社区成员
发帖
与我相关
我的任务
分享
<table id="t1">
<tr>
<td>
</td>
<td>
Head
</td>
</tr>
<tr>
<td>
Rows
</td>
<td onclick="ShowTitle('tl');">
Shows
</td>
</tr>
</table>
<script>
function ShowTitle(id)
{
var TDIndex=1;//既然是动态生成的,这个TDIndex可以在后台程序中获得的。
var objTable=document.getElementById("t1");
alert(objTable.rows[0].cells[TDIndex].innerHTML);
}
</script>
<html>
<head><title></title>
<script type="text/javascript">
function getValue()
{
var rowIndex=event.srcElement.parentElement.rowIndex;
var cellIndex=event.srcElement.cellIndex;
var c=document.getElementById("column"+rowIndex);
var r=document.getElementById("row"+cellIndex);
alert("行表头隐藏控件值:"+r.value);
alert("列表头隐藏控件值:"+c.value);
}
</script>
</head>
<body>
<table border="1px" stytle="Width:150;height:150">
<tr>
<td> </td>
<td>行表头1 <input type="hidden" name="row" id="row1" value="r1"> </td>
<td>行表头2 <input type="hidden" name="row" id="row2" value="r2"> </td>
</tr>
<tr>
<td>列标题1 <input type="hidden" name="column" id="column1" value="c1"> </td>
<td onclick="getValue()">aaa1 </td>
<td onclick="getValue()">aaa2 </td>
</tr>
<tr>
<td>列标题2<input type="hidden" name="column" id="column2" value="c2"> </td>
<td onclick="getValue()">bbb1</td>
<td onclick="getValue()">aaa2 </td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<title></title>
<body>
<form id="form1">
<table border="1px" styte="Width:150;height:150" id="theTable">
<tr id="tr1">
<td id="td1" > </td>
<td id="td2" > 标题 <input type="hidden" name="row" id="row" value="1"/> </td>
</tr>
<tr id="tr2">
<td id="td3">列标题 <input type="hidden" name="column" id="column" value="2"/> </td>
<td id="td4">aaa </td>
</tr>
</table>
<script language="javascript" type="text/javascript">
function test1()
{
var theTable = document.getElementById("theTable");
for (i = 0; i < theTable.rows.length; i++) //循环tr
{
for (ii = 0; ii < theTable.rows[i].cells.length; ii++) //循环td
{
if (theTable.rows[i].cells[ii] == null)
{
continue;
}
else
{
for (iii = 0; iii < document.getElementById("theTable").rows[i].cells[ii].childNodes.length; iii++) //循环td里面的控件
{
var obj = theTable.rows[i].cells[ii].childNodes[iii];
if(obj.id!=null)
alert(obj.id);
}
}
}
}
}
test1();
function test2() {
for (i = 0; i < document.forms[0].elements.length; i++) {
obj = document.forms[0].elements[i];
if (obj.type == "hidden") {
alert(obj.value);
}
}
}
test()2;
</script>
</form>
</body>
</html>