-
-11 13
-
在严老师严sir的博客上看到的他写的这个jquery删除table的tr的,和他讨论了一番加上php应该咋个弄,其实很简单,因为jquery中的ajax是在是很好用,所以决定亲手写下!中间范了个错误,今天在严sir的帮助下解决了!废话少说,先给php爱好者的读者分享分享代码!
js代码:
<script language="javascript" src="js/jquery.js"></script>
<script language="javascript">
$().ready(function(){
$("a.del").click(function(){
if(confirm("确定删除?"))
{
var id = $(this).attr("value");
var str="ac=del"+"&id="+id;
$.ajax({
type:"post",
url:"jquery_del_trAct.php",
data:str,
dataType:"html",
success:function(data){
if(data == 1){
alert("删除成功!");
}else{
alert("操作失败!");
return false;
}
}
});
$(this).parent("td").parent("tr").remove();
}
else
{
return false;
}
});$("#msg").ajaxStart(function(){
$(this).html("正在加载。。。。");
});
$("#msg").ajaxSuccess(function(){
$(this).html("加载完成!");
});
});
</script>html和php混合代码:
<?php
require_once('config.inc.php');
require_once('include/dbConnection.class.php');
$db = new dbConnection(DSN);
$query = "select * from member";
$db -> execute($query);
$result = $db -> fetch();
?><div style="height:100px; width:200px;" id="msg"></div>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
<?php
foreach($result as $v){
?>
<tr class="deltr">
<td width="300" height="25" align="left" bgcolor="#EEEEEE"><?php echo $v['userName'];?></td>
<td width="100" align="center" bgcolor="#EEEEEE"><a value="<?php echo $v['id'];?>" href="javascript:;" class="del">删除</a></td>
</tr>
<?php
}
?>
</table>php处理代码:
<?php
require_once('config.inc.php');
require_once('include/dbConnection.class.php');
$db = new dbConnection(DSN);
$ac = $_REQUEST['ac'];
if($ac == "del"){
$id = intval($_POST['id']);
$query = "delete from member where id ={$id}";
$db -> execute($query,2);
if($db ->affectedRows > 0){
echo 1;
}else{
echo 0;
}
}
?>注意:php代码都是按照我自己管用的写法写的,大家就按照自己的写就对了!
本文来源于php爱好者:php教程 —http://www.phplover.cn/
原文地址:http://www.phplover.cn/post/jquery-php-delete-table-tr.html
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
1楼 qlj
Post:2009-11-13 15:14:51
为什么使用ASP 的BLOG