jQuery實(shí)現(xiàn)點(diǎn)擊表格單元格就可以編輯內(nèi)容的方法【測(cè)試可用】
本文實(shí)例講述了jQuery實(shí)現(xiàn)點(diǎn)擊表格單元格就可以編輯內(nèi)容的方法。分享給大家供大家參考,具體如下:
運(yùn)行效果截圖如下:
具體代碼如下:
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jquery表格可編輯修改表格里面的數(shù)值</title> <meta name="description" content="jquery表格特效制作jquery表格可編輯任意修改里面的數(shù)值" /> <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> <script type="text/javascript"> $(function(){ $('table td').click(function(){ if(!$(this).is('.input')){ $(this).addClass('input').html('<input type="text" value="'+ $(this).text() +'" />').find('input').focus().blur(function(){ $(this).parent().removeClass('input').html($(this).val() || 0); }); } }).hover(function(){ $(this).addClass('hover'); },function(){ $(this).removeClass('hover'); }); }); </script> <style type="text/css"> /* page styles */ body{font-family:"Segoe UI", Frutiger,Tahoma,Helvetica,"Helvetica Neue", Arial, sans-serif;font-size:62.5%;} table{border-collapse:collapse;} td, th{text-align:center;border:1px solid #ddd;padding:2px 5px;} caption{margin:0 0 .5em;font-weight:bold;} /*demo styles*/ table{width:500px;height:200px;margin-left:30px;} td, th{font-size:1.2em;padding:2px;width:13%;} th{background-color:#f4f4f4;} caption{font-size:1.5em;} table{float:left;margin:40px 40px 0 0;} .demo{width:500px;margin:0 auto;} /* input */ td input{border:1px solid orange;background:yellow;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;position:absolute;padding:8px 0;text-align:center;width:60px;margin:-17px 0 0 4px;font-size:1.4em;} td.input{ padding:0;position:relative;} td.hover{background:#eee;} </style> </head> <body> <div class="demo"> <table> <caption>2009年員工產(chǎn)品銷售走勢(shì)圖</caption> <thead> <tr> <td></td> <th scope="col">food</th> <th scope="col">auto</th> <th scope="col">household</th> <th scope="col">furniture</th> <th scope="col">kitchen</th> <th scope="col">bath</th> </tr> </thead> <tbody> <tr> <th scope="row">Mary</th> <td>190</td> <td>160</td> <td>40</td> <td>120</td> <td>30</td> <td>70</td> </tr> <tr> <th scope="row">Tom</th> <td>3</td> <td>40</td> <td>30</td> <td>45</td> <td>35</td> <td>49</td> </tr> <tr> <th scope="row">Brad</th> <td>10</td> <td>180</td> <td>10</td> <td>85</td> <td>25</td> <td>79</td> </tr> <tr> <th scope="row">Kate</th> <td>40</td> <td>80</td> <td>90</td> <td>25</td> <td>15</td> <td>119</td> </tr> </tbody> </table> </div> </body> </html>
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery表格(table)操作技巧匯總》、《jQuery form操作技巧匯總》、《jQuery常用插件及用法總結(jié)》、《jQuery操作json數(shù)據(jù)技巧匯總》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery常見(jiàn)經(jīng)典特效匯總》、《jQuery動(dòng)畫(huà)與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- JQuery 動(dòng)態(tài)生成Table表格實(shí)例代碼
- 基于jQuery實(shí)現(xiàn)表格的排序
- jQuery+json實(shí)現(xiàn)動(dòng)態(tài)創(chuàng)建復(fù)雜表格table的方法
- jQuery實(shí)現(xiàn)的表格展開(kāi)伸縮效果實(shí)例
- 基于jQuery實(shí)現(xiàn)表格內(nèi)容的篩選功能
- jquery表格datatables實(shí)例解析 直接加載和延遲加載
- 基于jQuery實(shí)現(xiàn)表格的查看修改刪除
- jQuery實(shí)現(xiàn)表格行和列的動(dòng)態(tài)添加與刪除方法【測(cè)試可用】
- jQuery實(shí)現(xiàn)的可編輯表格完整實(shí)例
- 詳解jQuery簡(jiǎn)單的表格應(yīng)用
相關(guān)文章
jquery attr方法獲取input的checked屬性問(wèn)題
如果使用jquery,應(yīng)使用prop方法來(lái)獲取和設(shè)置checked屬性,不應(yīng)使用attr,需要的朋友可以參考下2014-05-05jQuery zTree樹(shù)插件動(dòng)態(tài)加載實(shí)例代碼
這篇文章主要介紹了jQuery zTree樹(shù)插件動(dòng)態(tài)加載效果的實(shí)例代碼,需要的朋友可以參考下2017-05-05實(shí)例詳解jQuery結(jié)合GridView控件的使用方法
這篇文章主要以實(shí)例的方式詳細(xì)介紹了jQuery結(jié)合GridView控件的使用方法,感興趣的小伙伴們可以參考一下2016-01-01jQuery設(shè)置聚焦并使光標(biāo)位置在文字最后的實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇jQuery設(shè)置聚焦并使光標(biāo)位置在文字最后的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-08jQuery插件echarts設(shè)置折線圖中折線線條顏色和折線點(diǎn)顏色的方法
這篇文章主要介紹了jQuery插件echarts設(shè)置折線圖中折線線條顏色和折線點(diǎn)顏色的方法,結(jié)合實(shí)例形式分析了jQuery圖表插件echarts設(shè)置折線圖的相關(guān)操作技巧,需要的朋友可以參考下2017-03-03jQuery實(shí)現(xiàn)的checkbox級(jí)聯(lián)選擇下拉菜單效果示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的checkbox級(jí)聯(lián)選擇下拉菜單效果,涉及jQuery鼠標(biāo)事件響應(yīng)及表格table動(dòng)態(tài)操作的相關(guān)技巧,需要的朋友可以參考下2016-12-12