日期:2014-05-16  浏览次数:20378 次

javascript 简单问题求解!!!
在如下一个简单的html页面,代码如下:
<html>
<body>
<table>
<tr   id= "t1 ">
    <td> <input   type= "text "   name= "a1 "   value= "a1 "> </td>
    <td> <input   type= "text "   name= "b1 "   value= "b1 "> </td>
    <td> <input   type= "button "   name= "submit1 "   value= "修改 "> </td>
</tr>
<tr   id= "t2 ">
    <td> <input   type= "text "   name= "a2 "   value= "a2 "> </td>
    <td> <input   type= "text "   name= "b2 "   value= "b2 "> </td>
    <td> <input   type= "button "   name= "submit2 "   value= "修改 "> </td>
</tr>
<tr   id= "t3 ">
    <td> <input   type= "text "   name= "a3 "   value= "a3 "> </td>
    <td> <input   type= "text "   name= "b3 "   value= "b3 "> </td>
    <td> <input   type= "button "   name= "submit3 "   value= "修改 "> </td>
</tr>
</table>
</body>
</html>

我想当点击修改按钮时,   通过javascript获得当前行文本框中的值,例如:
当点击按钮submit1时,   得到文本框a1,b2中的值;
当点击按钮submit2时,   得到文本框a2,b2中的值等,   依次类推!!!

请各位大虾帮忙解决,   小弟不甚感激!!!!谢谢.......



------解决方案--------------------
<html>
<script language= "JavaScript " type= "text/javascript ">
function getValue(obj)
{
var objTR = obj.parentNode.parentNode;
var s1=objTR.cells[0].childNodes[0].value;
var s2=objTR.cells[1].childNodes[0].value;
alert(s1+ "\n "+s2);
}
</script>
<body>
<table>
<tr id= "t1 ">
<td> <input type= "text " name= "a1 " value= "a1 "> </td>
<td> <input type= "text " name= "b1 " value= "b1 "> </td>
<td> <input type= "button " name= "submit1 " value= "修改 " onclick= "getValue(this); "> </td>
</tr>
<tr id= "t2 ">
<td> <input type= "text " name= "a2 " value= "a2 "> </td>
<td> <input type= "text " name= "b2 " value= "b2 "> </td>
<td> <input type= "button " name= "submit2 " value= "修改 " onclick= "getValue(this); "> </td>
</tr>
<tr id= "t3 ">
<td> <input type= "text " name= "a3 " value= "a3 "> </td>
<td> <input type= "text " name= "b3 " value= "b3 "> </td>
<td> <input type= "button " name= "submit3 " value= "修改 " onclick= "getValue(this); "> </td>
</tr>
</table>
</body>
</html>