87,910
社区成员
发帖
与我相关
我的任务
分享
var as=document.getElementsByName('a');
var bs=document.getElementsByName('b');
for(var i=0;i<as.length;i++){
as[i].i=i;
as[i].onkeyup=function(){
bs[this.i].value=this.value+' ....';
}
}
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<title>无标题文档</title>
</head>
<body>
<table>
<tr>
<td><input type=text value="" name=a></td>
<td><input type=text value="" name=b></td>
</tr>
<tr>
<td><input type=text value="" name=a></td>
<td><input type=text value="" name=b></td>
</tr>
<tr>
<td><input type=text value="" name=a></td>
<td><input type=text value="" name=b></td>
</tr>
</table>
<script type="text/javascript">
jQuery(function($){
$('input[name=a]').keyup(function(){
$(this).parents('tr').find('input[name=b]').val($(this).val() + 'b');
});
});
</script>
</body>
</html>