PHP+jQuery實(shí)現(xiàn)雙擊修改table表格功能示例
本文實(shí)例講述了PHP+jQuery實(shí)現(xiàn)雙擊修改table表格功能。分享給大家供大家參考,具體如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>即點(diǎn)即改</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(){
//獲取到 當(dāng)前 input 下的元素(原值)
window.olds = $(this).children('input').val();
if(olds==undefined)
{
return false;
}
var signs = $(this).attr('signs'); //獲取屬性值(這些值方便php后臺(tái)的操作)
var user_id = $(this).parent().attr("id"); //接受當(dāng)前點(diǎn)擊的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); //方便下面失去焦點(diǎn)事件 找ID(沒有這個(gè)無(wú)法定位到tr里面的id屬性)
//循環(huán)這些值從而判斷是修改數(shù)據(jù)的類型,對(duì)一些特殊類型的數(shù)據(jù)進(jìn)行特殊處理
switch(signs){
case 'user_name':
$("#" + signs + "_" + user_id).focus().on("blur",function(){
var content = $(this).val();
if(content!=olds) //與原值不同則傳到后臺(tái)
{
// alert(user_id);alert(signs);alert(content);
/*
通過(guò)getJSON將數(shù)據(jù)傳輸?shù)胶笈_(tái)
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>
運(yùn)行效果如下:

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP數(shù)組(Array)操作技巧大全》、《PHP常用遍歷算法與技巧總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- JS/jQuery實(shí)現(xiàn)超簡(jiǎn)單的Table表格添加,刪除行功能示例
- jquery實(shí)現(xiàn)自定義樹形表格的方法【自定義樹形結(jié)構(gòu)table】
- JS拖動(dòng)選擇table里的單元格完整實(shí)例【基于jQuery】
- jQuery-ui插件sortable實(shí)現(xiàn)自由拖動(dòng)排序
- 使用jQuery給Table動(dòng)態(tài)增加行、清空table的方法
- js與jQuery實(shí)現(xiàn)獲取table中的數(shù)據(jù)并拼成json字符串操作示例
- jQuery實(shí)現(xiàn)table表格checkbox全選的方法分析
- jQuery+datatables插件實(shí)現(xiàn)ajax加載數(shù)據(jù)與增刪改查功能示例
- JQuery實(shí)現(xiàn)table中tr上移下移的示例(超簡(jiǎn)單)
- 基于jQuery獲取table數(shù)據(jù)發(fā)送到后端
相關(guān)文章
Php 構(gòu)造函數(shù)construct的前下劃線是雙的_
最近寫php的class時(shí),總是碰到function non object的錯(cuò)誤,知道是類沒有實(shí)例化,但就是不知道錯(cuò)誤在哪里。2009-12-12
php連接odbc數(shù)據(jù)源并保存與查詢數(shù)據(jù)的方法
這篇文章主要介紹了php連接odbc數(shù)據(jù)源并保存與查詢數(shù)據(jù)的方法,涉及odbc數(shù)據(jù)源的操作技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-12-12
關(guān)于使用coreseek并為其做分頁(yè)的介紹
本篇文章是對(duì)使用coreseek并為其做分頁(yè)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
PHP7中對(duì)十六進(jìn)制字符串處理的問題詳解
在本篇文章里小編給大家整理的是一篇關(guān)于PHP7中對(duì)十六進(jìn)制字符串處理的問題詳解內(nèi)容,有需要的朋友們可以跟著學(xué)習(xí)下。2021-11-11
兼容性最強(qiáng)的PHP生成縮略圖的函數(shù)代碼(修改版)
寫通用性程序考慮兼容性是很頭痛的事情,關(guān)于用PHP生成縮略圖的代碼很多,不過(guò)能完全兼容gd1.6和gd2.x,并能保證縮圖清晰性的代碼幾乎沒有,我把我以前的代碼改了一下,就能實(shí)現(xiàn)了。2011-01-01
PHP下通過(guò)file_get_contents的代理使用方法
2011-02-02

