原文地址:http://www.freejs.net/article_biaodan_43.html
之前已经发了2篇类似的文章《点击变td为input更新》和《jquery表格可编辑修改表格里面的值,点击td变input无刷新更新表格》
这篇功能是一样的,不过实用性可能比不上前面的文章

PHP Code
- <table>
- <Tr><Td colspan="2">如果本例看不到数据请先添加一条记录,点击<a href="?action=add">这里可以添加</a></Td></Tr>
- <?php
- $sql="select * from `add_delete_record` where id>0";
- $rs=mysql_query($sql);
- if ($row = mysql_fetch_array($rs))
- {
- do {
- ?>
-
- <Tr bgcolor="#eeeeee">
- <Td><?php echo $row[‘id‘]?></Td>
- <Td class="bigclassname" ><span title="点击修改"><?php echo $row[‘text‘]?></span></Td>
- </Tr>
- <?php
- }
-
- while ($row = mysql_fetch_array($rs));
- }?>
- </table>
JavaScript Code
- <script>
-
- $(function() {
- $(".bigclassname").click(function() {
-
- var objTD = $(this);
-
- var oldText = $.trim(objTD.text());
-
- var input = $("<input type=‘text‘ value=‘" + oldText + "‘ />");
-
- objTD.html(input);
-
- input.click(function() {
- return false;
- });
-
- input.css("font-size", "16px");
- input.css("text-align", "center");
- input.css("background-color", "#ffffff");
- input.width("120px");
-
- input.select();
-
- input.blur(function() {
-
- var newText = $(this).val();
-
- objTD.html(newText);
-
- var bigclassid = objTD.prev().text();
-
- newText = escape(newText);
-
- var url = "update.php?id=" + bigclassid + "&bigclassname=" + newText;
-
- $.get(url, function(data) {});
-
- });
- });
- });
- </script>
[转]jquery 点击表格变为input可以修改无刷新更新数据
原文:http://www.cnblogs.com/dirgo/p/5075254.html