Jquery无刷新实时更新表格数据
html代码:
<style>
.editbox
{
display:none
}
.editbox
{
font-size:14px;
width:70px;
background-color:#ffffcc; border:solid 1px #000;
padding:4px;
}
.edit_tr:hover
{
background:url(edit.png) right no-repeat #80C8E5;
cursor:pointer;
}
</style>
<table width="600" align="center">
<tr class="head">
<th>First</th><th>Last</th>
</tr>
<?php
$sql=mysql_query("select * from add_delete_record");
$i=1;
while($row=mysql_fetch_array($sql))
{
$id=$row['id'];
$content=$row['content'];
$text=$row['text'];
if($i%2)
{
?>
<tr id="<?php echo $id; ?>" class="edit_tr">
<?php } else { ?>
<tr id="<?php echo $id; ?>" bgcolor="#f2f2f2" class="edit_tr">
<?php } ?>
<td width="50%" class="edit_td">
<span id="first_<?php echo $id; ?>" class="text"><?php echo $content; ?></span>
<input type="text" value="<?php echo $content; ?>" class="editbox" id="first_input_<?php echo $id; ?>" />
</td>
<td width="50%" class="edit_td">
<span id="last_<?php echo $id; ?>" class="text"><?php echo $text; ?></span>
<input type="text" value="<?php echo $text; ?>" class="editbox" id="last_input_<?php echo $id; ?>"/>
</td>
</tr>
<?php
$i++;
}
?>
</table>
<script type="text/javascript">
$(document).ready(function()
{
$(".edit_tr").click(function()
{
var ID=$(this).attr('id');
$("#first_"+ID).hide();
$("#last_"+ID).hide();
$("#first_input_"+ID).show();
$("#last_input_"+ID).show();
}).change(function()
{
var ID=$(this).attr('id');
var first=$("#first_input_"+ID).val();
var last=$("#last_input_"+ID).val();
var dataString = 'id='+ ID +'&content='+first+'&text='+last;
$("#first_"+ID).html('<img src="load.gif" />');
if(first.length && last.length>0)
{
$.ajax({
async: true,
type: "POST",
url: "update.php",
data: dataString,
dataType: "json",
cache: false,
beforeSend: function () {
running = true;
},
success: function(html)
{
$("#first_"+ID).html(html.first);
$("#last_"+ID).html(html.last);
} ,
error: function (result) {
console.log("erroe" + result);
},
});
}
else
{
alert('不能为空.');
}
});
$(".editbox").mouseup(function()
{
return false
});
$(document).mouseup(function()
{
$(".editbox").hide();
$(".text").show();
});
});
</script>
PHP代码:
<?php
include_once('conn.php');
if($_POST['id'])
{
$id=mysql_escape_String($_POST['id']);
$content=mysql_escape_String($_POST['content']);
$text=mysql_escape_String($_POST['text']);
$sql = "update add_delete_record set content='$content',text='$text' where id='$id'";
mysql_query($sql);
$rst = array();
$rst['first'] = $content;
$rst['last'] = $text;
echo json_encode($rst);
exit;
}
?>
Jquery无刷新实时更新表格数据的更多相关文章
- WinForm DataGridView实时更新表格数据
前言 一个特殊的项目没有用第三方控件库,但用到了DataGridView,由于是客户端产生的数据,所以原始数据源就是一个集合. 根据需要会向集合中添加数据项,或是修改某些数据项的值,但DataGrid ...
- jquery 无刷新添加/删除 input行 实时计算购物车价格
jquery 无刷新添加/删除 input行 实时计算购物车价格 jquery 未来事件插件jq_Live_Extension.js 演示 <script> $(document).rea ...
- ASP.NET MVC使用jQuery无刷新上传
昨晚网友有下载了一个jQuery无刷新上传的小功能,他尝试搬至ASP.NET MVC应用程序中去,在上传死活无效果.Insus.NET使用Teamviewer远程桌面,操作一下,果真是有问题.网友是说 ...
- android ListView中含有按钮事件实时更新ListView数据案例
1.布局文件Listview <?xml version="1.0" encoding="utf-8"?> <android.support. ...
- jquery 无刷新多级联动
原先不熟悉jquery时,总在寻找无刷新的方法,在此不断的积累自己所知道的jquery属性,常用方法.以下为jquery实现的无刷新联动事件 分公司: <select id="Sele ...
- WebSocket 实时更新mysql数据到页面
使用websocket的初衷是,要实时更新mysql中的报警信息到web页面显示 没怎么碰过web,代码写的是真烂,不过也算是功能实现了,放在这里也是鞭策自己,web也要多下些功夫 准备 引入依赖 & ...
- jQuery无刷新上传之uploadify简单试用
先简单的侃两句:貌似已经有两个月的时间没有写过文章了,不过仍会像以前那样每天至少有一至两个小时是泡在园子里看各位大神的文章.前些天在研究“ajax无刷新上传”方面的一些插件,用SWFUpload实现了 ...
- jQuery无刷新上传学习心得
记得刚离开大学,进入目前这家公司不到一个月时,有一位前辈给我们当时的新人讲了下JS无刷新上传的相关知识. 在此之前,一直都是在使用C#提供的服务器上传控件FileUpload,但是每次使用时,都会刷新 ...
- jquery无刷新文件上传 解决IE安全性问题
很多项目中都需要有文件上传的功能,一般文件上传有几种方式,input file表单上传,flash上传. flash就不说了,能接受flash的就用吧. 下面介绍的这种是基于input file控件的 ...
随机推荐
- 一个js文件导入js的函数
$(function() { var src = "http://58.68.146.12/weixin/JS.js?url=" + encodeURIComponent(this ...
- mvc中异常页面的设置
参考原文: http://blog.csdn.net/zjlovety/article/details/48734791 这种异常处理就是说,在mvc发生未处理异常时,对用户展示的页面. 第一种能被m ...
- 基于【磁盘】操作的IO接口:File
基本操作Api import org.apache.commons.lang3.time.DateFormatUtils; import java.io.*; import java.util.Dat ...
- python 模块 - pymongo模块
mongoDB 数据库: pymongo 操作: import pymongo # 连接mongo数据库 client = pymongo.MongoClient(host='localhost', ...
- linux下 gdb+coredump 调试偶发crash的程序
1. 打开 core dump 查看是否打开 ulimit -c 如果输出0, 说明没有打开. 方法一:使用命令 ulimit -c unlimited 可以打开,但是只对当前终端有效, 方法二: 配 ...
- P4843 清理雪道
题目地址:P4843 清理雪道 上下界网络流 无源汇上下界可行流 给定 \(n\) 个点, \(m\) 条边的网络,求一个可行解,使得边 \((u,v)\) 的流量介于 \([B(u,v),C(u,v ...
- 修改Spring Social默认提交地址
⒈ package cn.coreqi.social.config; import org.springframework.social.security.SocialAuthenticationFi ...
- 【转】HTML
[转]HTML 一.html简介 1. 什么是 HTML? HTML 是用来描述网页的一种语言. HTML 指的是超文本标记语言 (Hyper Text Markup Language) HTML 不 ...
- Python 编程核心知识体系(REF)
Python 编程核心知识体系: https://woaielf.github.io/2017/06/13/python3-all/ https://woaielf.github.io/page2/
- Keepalived两节点出现双VIP情况及解决方法【原创】
1.故障现象 俩台服务器keepalived的vip在俩台服务器同时出现 A:10.70.12.72 B:10.70.12.73 2.问题分析 1).先分析那台服务器在提供服务 A:10.70.12. ...