希望高手帮我解决下,谢谢
<script>
function aa(){
var trobj = document.getElementById( "trname1 ");
//这里如何可以得到 id= "trname1 "的tr中name=“1”的input的value值,
alert(str);//这里可以打印在页面上
}
</script>
<input type= "button " value= "获取值 " onclick= "aa() ">
<TABLE id= "tableName " BORDER=1 WIDTH=80%>
<THEAD>
<TR>
<TH> Heading 1 </TH>
<TH> Heading 2 </TH>
</TR>
</THEAD>
<TBODY>
<TR id= "trname1 ">
<TD>
<input type= "Text " name= "1 " value= "11111111111 ">
<input type= "Text " name= "2 " value= "222222222222 ">
</TD>
</TR>
<TR id= "trname2 ">
<TD>
<input type= "Text " name= "1 " value= "3333333333333333 ">
<input type= "Text " name= "2 " value= "4444444444444444 ">
</TD>
</TR>
</TBODY>
</TABLE>
------解决方案--------------------var e=document.getElementById( 'trname1 ');
e.childNodes[0].childNodes[0].value;
或者直接
<input type= "Text " name= "1 " value= "11111111111 "> 分配id
------解决方案--------------------function aa(){
var trobj = document.getElementById( "trname1 ");
var str=trobj.firstChild.firstChild.value;
alert(str);
}
------解决方案-------------------- <html>
<head>
<script language= "javascript ">
function aa(){
var trobj = document.getElementById( "trname1 ");
for(var i = 0;i < trobj.childNodes.length;i++){
var tdobj = trobj.childNodes[i];
for(var j = 0;j < tdobj.childNodes.length;j++){
if(tdobj.childNodes[j].name == '1 '){
alert(tdobj.childNodes[j].value);
}
}
}
alert(str);
}
</script>
</head>
<body>
<input type= "button " value= "获取值 " onclick= "aa() ">
<TABLE id= "tableName " BORDER=1 WIDTH=80%>
<THEAD>
<TR>
<TH> Heading 1 </TH>
<TH> Heading 2 </TH>
</TR>
</THEAD>
<TBODY>
<TR id= "trname1 ">
<TD>
<input type= "Text " name= "2 " value= "222222222222 ">
<input type= "Text " name= "1 " value= "11111111111 ">
</TD>
</TR>
<TR id= "trname2 ">
<TD>
<input type= "Text " name= "1 " value= "3333333333333333 ">
<input type= "Text " name= "2 " value= "4444444444444444 ">
</TD>
</TR>
</TBODY>
</TABLE>
</body>
</html>
这样即使name= "1 "的input位置变化也会取得到