js怎么操作指定行啊 表格有2行,每行有1个文本框和一个按钮,如何点击该行的按钮就让这一行的文本框的值变成1啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <input type="button" value="变" onclick="change();" />function change(){document.getElementById("txt_tid").value = "1";} <table><tr><td>文本框</td><td>按钮</td></tr><tr><td><input type=text id=txt_tid /></td><td><input type="button" value="变" onclick="change();" /></td></tr><tr><td><input type=text id=txt_tid /></td><td><input type="button" value="变" onclick="change();" /></td></tr></table> 你贴全不行吗?。。你这样怎么帮你解决啊。。只有乱猜了。。<input type="button" value="变" onclick="change(1);" /><input type="button" value="变" onclick="change(2);" />function change(i){document.getElementById("txt_tid"+i).value = "1";}这是最笨的方法给2个文本框都加一个id属性。。然后通过button的点击事件把id传过去。。 <!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> HTML贴了啊,文本框的ID是一样的啊 getElementById这个是搜索页面中ID符合的第一个元素,肯定会都只在第一个文本框里了 js实现复选框的全选与反选 javascript求解bug JS能不能把所有input type="button" 都blur() 了??? JS switch 如何数字递增? javascrpt在新装的win2003不能运行! 移动图标!小问题 200分给你!duoduobaba(避雷针)进来! 请问怎么样才能实现这种失效的效果? 帮我看看代码,提交不上呀 document.designMode是什么意思? data-value的值应该如何获取? 怎样给div设置真正的false?
function change()
{
document.getElementById("txt_tid").value = "1";
}
<tr>
<td>
文本框
</td>
<td>
按钮
</td>
</tr>
<tr>
<td>
<input type=text id=txt_tid />
</td>
<td>
<input type="button" value="变" onclick="change();" />
</td>
</tr>
<tr>
<td>
<input type=text id=txt_tid />
</td>
<td>
<input type="button" value="变" onclick="change();" />
</td>
</tr>
</table>
<input type="button" value="变" onclick="change(1);" />
<input type="button" value="变" onclick="change(2);" />
function change(i)
{
document.getElementById("txt_tid"+i).value = "1";
}
这是最笨的方法给2个文本框都加一个id属性。。然后通过button的点击事件把id传过去。。
<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>想要这样?
<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>