前台特效(3) 编辑表格
2013-03-10 11:19
120 查看
<!DOCTYPE html> <html> <head> <title>编辑表格</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="http://common.cnblogs.com/script/jquery.js"></script> <script> $(function(){ var off = true; $("#table td").each(function(){ $(this).click(function(){ if(off){ var cont = $(this).html(); $(this).html(''); $(this).append("<input type='text' id='cont' value='"+cont+"'/>"); $("#cont").focus().css("background-color","#ffffcc"); off = false; } }) }); $("#cont").live({blur:function(){ $(this).parent().html($(this).val()); off = true; },keydown:function(event){ if(event.keyCode == 13){ $(this).parent().html($(this).val()); off = true; } }}); }) </script> <style> #table{ border: solid 3px #cccccc; text-align: center; padding: 5px; } #table td{ width:200px; height:30px; border: solid 3px #cccccc; } </style> </head> <body> <table id="table"> <tr> <td>11</td> <td>12</td> <td>13</td> <td>14</td> <td>15</td> </tr> <tr> <td>21</td> <td>22</td> <td>23</td> <td>24</td> <td>25</td> </tr> <tr> <td>31</td> <td>32</td> <td>33</td> <td>34</td> <td>35</td> </tr> <tr> <td>41</td> <td>42</td> <td>43</td> <td>44</td> <td>45</td> </tr> </table> </body> </html>
基本思路:
1.点击table的td时触发click时间,获取td内容并赋予新添加的input,删除td的内容,添加input
2.点击同时,使input获取焦点并改变背景颜色
3.当input失去焦点或者按下Enter键时,获取input的value,覆盖到td
希望对你有所帮助! ^_^~
相关文章推荐
- jquery特效之可编辑的表格
- 基于JQuery制作可编辑的表格特效
- 在网页可编辑的表格Jquery dataTable从前台到后台完整
- Ext.js5的表格插件—checkbox/编辑等常见需求(15)
- Ajax实现可编辑的表格(实例)
- 为什么使用百度编辑器时 前台代码不能放在 class<table >中 如果放进去的话,会发生 百度编辑的内容显示不出来
- 在可编辑表格EditorGrid中,我选择一行已输入的数据,点击删除按钮,该行数据将被删除,然后当我点击表单提交按钮时,已经被删除的那一行数据仍然被插入数据库中
- [模板]为dgrid表格中的cell添加可编辑复制属性(自用)
- easyUi可编辑表格
- 使用Jquery实现可编辑的表格 并使用AJAX提交到服务器修改数据
- 使用Jquery实现可编辑的表格 并使用AJAX提交到服务器修改数据
- javascript编辑表格二
- JQuery 实站第二讲:可编辑的表格
- jquery.datatables.js表格编辑与删除
- 做一个可编辑的表格控件。
- SWT/JFACE表格Table可编辑
- CAD编辑指南6:CAD导入图片和在CAD中创建表格
- 在ASP.NET中应用Excel:(8)为HTML表格增加编辑功能
- jQuery EasyUI中对表格进行编辑的实现代码
- Extjs学习总结之EditGridPanel可编辑表格