日期:2014-05-16 浏览次数:20588 次
<!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>
<title></title>
<script> function change(i) {
document.getElementById("txt_tid"+i).value = "1";
}</script>
</head>
<body>
<table>
<tr>
<td>
文本框
</td>
<td>
按钮
</td>
</tr>
<tr>
<td>
<input type="text" id="txt_tid1" />
</td>
<td>
<input type="button" value="变" onclick="change(1);" />
</td>
</tr>
<tr>
<td>
<input type="text" id="txt_tid2" />
</td>
<td>
<input type="button" value="变" onclick="change(2);" />
</td>
</tr>
</table>
</body>
</html>
------解决方案--------------------
id重复 了? 贴出你的HTML部分。
------解决方案--------------------
不确定ID的情况操作一行内的文本框:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function Test()
{
var evt=window.event||arguments[0];
var parent=evt.srcElement.parentElement.parentElement;
var txts=parent.getElementsByTagName("input");
for(var i=0;i<txts.length;i++)
{
if(txts[i].type=="text")
{
txts[i].value="1";
}
}
}
</script>
</head>
<body>
<table>
<tr>
<td>
<input type="text" value="a"/>
<input type="button" value="Test" onclick="Test();"/>
</td>
</tr>
<tr>
<td>
<input type="text" value="a"/>
<input type="button" value="Test" onclick="Test();"/>
</td>
</tr>
</table>
</body>
</html>
------解决方案--------------------