当前位置: 代码迷 >> Java Web开发 >> jQuery如何取得当前列的id
  详细解决方案

jQuery如何取得当前列的id

热度:2963   发布时间:2013-02-25 21:12:08.0
jQuery怎么取得当前列的id?
我要实现:单击用户名就可以修改,光标移走就保存。现在怎么也取不到对应的id,因为是循环产生的记录。

HTML code
<html>    <head>        <meta http-equiv=content-type content="text/html;charset=UTF-8" />        <title>Test</title>        <script type="text/javascript" src="jquery.js"></script>        <script type="text/javascript" src="edit.js"></script>    </head>    <body>        <table border="1" width="50%">            <tr>                <td width="50%">id</td>                <td class="note">用户名</td>            </tr>            <tr>                <td>2</td>                <td class="note">AAA</td>            </tr>            <tr>                <td>5</td>                <td class="note">BBB</td>            </tr>            <tr>                <td>1</td>                <td class="note">CCC</td>            </tr>            <tr>                <td>12</td>                <td class="note">DDD</td>            </tr>        </table>    </body></html>


JScript code
$(function(){    var mytext = $(".note");    mytext.click(function() {        var tdObj = $(this);        if (tdObj.children("input").length > 0) {            return false;        }        var text = tdObj();        tdObj("");        var inputObj = $("<input type='text'>").val(text).appendTo(tdObj);        inputObj.trigger("focus").trigger("select");        inputObj.click(function() {            return false;        });                inputObj.blur(function() {            var inputtext = $.trim($(this).val());            tdObj(inputtext);                                    alert("当前用户id:" + ???);                        $.post("edit.do?username=" + username + "&note=" + encodeURI(encodeURI(inputtext)));        });    });});


------解决方案--------------------------------------------------------
探讨
引用:

<table border="1" width="50%" id="test">
<tr>
<td width="50%">id</td>
<td class="note">用户名</td>
</tr>
<tr>
<t……

不对啊,每次得到的都是第一个值啊!

我实际应用中是用list循环的记录

------解决方案--------------------------------------------------------
学习了。。
  相关解决方案