怎么样用js或者jquery实现动态表格中 对于自身位置的识别?或许有些说的不太明白,举例页面布局
-----------------------
添加(button)名字1:(text) 名字2(text)           删除(button)
名字1:(text) 名字2(text)           删除(button)
_______________________________________________________页面上每点一下添加,则自动添加一行。
同时希望能够做到,我在名字1的text框的onfocus事件,能给相应行的名字2Text框赋值。
现在我定位不准我所在的行,所以给相应行的赋值总是失败,求大侠帮忙

解决方案 »

  1.   

    第一次加载和自动添加行的时候,所有的text都没有加唯一ID么?
      

  2.   

    没有。该怎么加呢?即使加了,又怎么将username的id的值取出来呢
      

  3.   

    看下这个是否是你需要的。注:jQuery必须是1.3或是1.3以上的版本才可以<!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> 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>