按下按钮,按钮所在的行的test2的值要变成123,而test3的值要变成456
<table>
<tr>
<td><input name="test1" type="button" value="Test" /></td>
<td><input name="test2" type="text" /></td>
<td><input name="test3" type="text" /></td>
</tr>
<tr>
<td><input name="test1" type="button" value="Test" /></td>
<td><input name="test2" type="text" /></td>
<td><input name="test3" type="text" /></td>
</tr>
<tr>
<td><input name="test1" type="button" value="Test" /></td>
<td><input name="test2" type="text" /></td>
<td><input name="test3" type="text" /></td>
</tr>
</table>
parentNode.nextSibling.firstChild.value='123'
parentNode.nextSibling.nextSibling.firstChild.value='456'
<script type="text/javascript">
window.attachEvent("onload", function () {
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
if (input.type == "button") {
input.attachEvent("onclick", function () {
window.event.srcElement.parentNode.nextSibling.firstChild.value = "123";
window.event.srcElement.parentNode.nextSibling.nextSibling.firstChild.value = "456";
});
}
}
});
</script>
这样应该可以.