日期:2014-05-17 浏览次数:20817 次
<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>
$(function(){ var mytext = $(".note"); mytext.click(function() { var tdObj = $(this); if (tdObj.children("input").length > 0) { return false; } var text = tdObj.html(); tdObj.html(""); 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.html(inputtext); alert("当前用户id:" + ???); $.post("edit.do?username=" + username + "¬e=" + encodeURI(encodeURI(inputtext))); }); }); });