PHP+jQuery實現(xiàn)雙擊修改table表格功能示例
更新時間:2019年02月21日 09:00:30 作者:ztblog
這篇文章主要介紹了PHP+jQuery實現(xiàn)雙擊修改table表格功能,涉及php數(shù)組讀取、遍歷及jQuery動態(tài)響應修改頁面元素屬性相關操作技巧,需要的朋友可以參考下
本文實例講述了PHP+jQuery實現(xiàn)雙擊修改table表格功能。分享給大家供大家參考,具體如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>即點即改</title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> </head> <body> <?php $con = array( array("id"=>1,"姓名"=>"張三","性別"=>"女"), array("id"=>2,"姓名"=>"李四","性別"=>"男"), array("id"=>3,"姓名"=>"王五","性別"=>"男")); // print_r($con);die; ?> <table align="center" border="1"> <?php foreach ($con as $key => $v): ?> <tr id="<?= $v['id'];?>"> <td signs="user_name" style="width:100px"> <input style="border:0; text-align: center; width:60px; background: #fff;" type="text" disabled="disabled" readonly="readonly" value="<?= $v['姓名'];?>" > </td> <td signs="user_sex" style="width:100px"> <input style="border:0; text-align: center; width:60px; background: #fff;" type="text" disabled="disabled" readonly="readonly" value="<?= $v['性別'];?>" > </td> </tr> <?php endforeach; ?> </table> </body> </html> <script> //雙擊觸發(fā)事件 $("tbody>tr>td").dblclick(function(){ //獲取到 當前 input 下的元素(原值) window.olds = $(this).children('input').val(); if(olds==undefined) { return false; } var signs = $(this).attr('signs'); //獲取屬性值(這些值方便php后臺的操作) var user_id = $(this).parent().attr("id"); //接受當前點擊的ID(tr里的id) //雙擊之后可以修改 $(this).find('input').attr("disabled",false); $(this).find('input').attr("readonly",false); $(this).find('input').css("border",'1px solid deepskyblue'); $(this).find('input').attr('id', signs + "_" + user_id); //方便下面失去焦點事件 找ID(沒有這個無法定位到tr里面的id屬性) //循環(huán)這些值從而判斷是修改數(shù)據的類型,對一些特殊類型的數(shù)據進行特殊處理 switch(signs){ case 'user_name': $("#" + signs + "_" + user_id).focus().on("blur",function(){ var content = $(this).val(); if(content!=olds) //與原值不同則傳到后臺 { // alert(user_id);alert(signs);alert(content); /* 通過getJSON將數(shù)據傳輸?shù)胶笈_ USER_ID SIGNS CONTENT */ } $(this).attr('disabled', 'disabled'); $(this).attr('readonly', 'readonly'); $(this).css('border', '0'); $(this).css('background', '#fff'); $(this).css('text-align', 'center'); }) break; case 'user_sex': $("#" + signs + "_" + user_id).focus().on("blur",function(){ var content = $(this).val(); if(content!=olds) { // alert(user_id); } $(this).attr('disabled', 'disabled'); $(this).attr('readonly', 'readonly'); $(this).css('border', '0'); $(this).css('background', '#fff'); $(this).css('text-align', 'center'); }) } }) </script>
運行效果如下:
更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP數(shù)組(Array)操作技巧大全》、《PHP常用遍歷算法與技巧總結》、《PHP數(shù)據結構與算法教程》、《php程序設計算法總結》、《PHP數(shù)學運算技巧總結》、《php字符串(string)用法總結》及《php常見數(shù)據庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
您可能感興趣的文章:
- JS/jQuery實現(xiàn)超簡單的Table表格添加,刪除行功能示例
- jquery實現(xiàn)自定義樹形表格的方法【自定義樹形結構table】
- JS拖動選擇table里的單元格完整實例【基于jQuery】
- jQuery-ui插件sortable實現(xiàn)自由拖動排序
- 使用jQuery給Table動態(tài)增加行、清空table的方法
- js與jQuery實現(xiàn)獲取table中的數(shù)據并拼成json字符串操作示例
- jQuery實現(xiàn)table表格checkbox全選的方法分析
- jQuery+datatables插件實現(xiàn)ajax加載數(shù)據與增刪改查功能示例
- JQuery實現(xiàn)table中tr上移下移的示例(超簡單)
- 基于jQuery獲取table數(shù)據發(fā)送到后端
相關文章
Php 構造函數(shù)construct的前下劃線是雙的_
最近寫php的class時,總是碰到function non object的錯誤,知道是類沒有實例化,但就是不知道錯誤在哪里。2009-12-12php連接odbc數(shù)據源并保存與查詢數(shù)據的方法
這篇文章主要介紹了php連接odbc數(shù)據源并保存與查詢數(shù)據的方法,涉及odbc數(shù)據源的操作技巧,非常具有實用價值,需要的朋友可以參考下2014-12-12PHP下通過file_get_contents的代理使用方法
2011-02-02