怎么样用js或者jquery实现动态表格中 对于自身位置的识别?或许有些说的不太明白,举例页面布局
-----------------------
添加(button)名字1:(text) 名字2(text) 删除(button)
名字1:(text) 名字2(text) 删除(button)
_______________________________________________________页面上每点一下添加,则自动添加一行。
同时希望能够做到,我在名字1的text框的onfocus事件,能给相应行的名字2Text框赋值。
现在我定位不准我所在的行,所以给相应行的赋值总是失败,求大侠帮忙
-----------------------
添加(button)名字1:(text) 名字2(text) 删除(button)
名字1:(text) 名字2(text) 删除(button)
_______________________________________________________页面上每点一下添加,则自动添加一行。
同时希望能够做到,我在名字1的text框的onfocus事件,能给相应行的名字2Text框赋值。
现在我定位不准我所在的行,所以给相应行的赋值总是失败,求大侠帮忙
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<script type="text/javascript" src="jquery1.4.2.js"></script>
<script type="text/javascript">
<!--
$(function () {
//给按钮添加事件
$("#but1").click(function () {
var str=' <tr><td>名字1:<input type="text" /></td><td>名字2:<input type="text" /></td><td><button onclick="del(this)">删除</button></td></tr>'
$("#tab").append(str); })
//给名字1的text添加事件
$("tr td:first-child").find("input").live("focus",function () {
$(this).parent().next().find("input").val($(this).val());
})
})
function del (obj) {
$(obj).parent().parent().remove();
}
//-->
</script>
</head>
<body>
<input type="button" value="添加" id="but1" />
<table border="1" id="tab">
<tr>
<td>名字1:<input type="text" /></td>
<td>名字2:<input type="text" /></td>
<td><button onclick="del(this)">删除</button></td>
</tr> </table>
</body>
</html>