php第二十五节课
详情删除
<!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>无标题文档</title>
<script src="jquery-1.11.2.min.js"></script>
<script src="tanchuang.js"></script>
<style type="text/css">
.xq{
background-color:#63F;
color:white;
}
.xq:hover{
background-color:#669;
cursor:pointer;
color:white;
}
</style>
<link href="tanchuang.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0" id="xianshi">
</table>
</body>
<script type="text/javascript">
$(document).ready(function(e) {
//显示数据
XianShi();
function XianShi()
{
$.ajax({
async:false,
url:"chuli.php",
data:{type:0},
type:"POST",
dataType:"TEXT",
success: function(data){
var hang = data.split("|");
var str = "<tr><td>代号</td><td>名称</td><td>操作</td></tr>";
for(var i=0;i<hang.length;i++)
{
var lie = hang[i].split("^");
str+="<tr><td><input type='checkbox' value='"+lie[0]+"' class='ck' />"+lie[0]+"</td><td>"+lie[1]+"</td><td><span class='xq' bs='"+lie[0]+"'>查看详情</span></td></tr>";
}
str+="<tr><td colspan='3'><input type='checkbox' id='qx' />全选 <input type='button' value='批量删除' id='del' /></td></tr>";
$("#xianshi").html(str);
}
});
//查看详情
$(".xq").click(function(){
//取主键值
var code = $(this).attr("bs");
$.ajax({
url:"chuli.php",
data:{code:code,type:1},
type:"POST",
dataType:"TEXT",
success: function(data){
var lie = data.split("^");
var html = "<div>民族代号:"+lie[0]+"</div><div>民族名称:"+lie[1]+"</div>";
var wd = new Window({
width : 400, //宽度
height : 500, //高度
title : '详细信息', //标题
content : html, //内容
isMask : true, //是否遮罩
buttons :"", //按钮
isDrag:true,
});
}
});
})
//全选
$("#qx").click(function(){
//全选按钮的选中状态
var xz = $(this)[0].checked;
//操作所有的复选框的选中状态
var ck = $(".ck");
ck.prop("checked",xz);
})
//删除
$("#del").click(function(){
//找选中的主键值
var ck = $(".ck");
var str = "";
for(var i=0;i<ck.length;i++)
{
if(ck.eq(i).prop("checked"))
{
str+=ck.eq(i).val()+"|";
}
}
str = str.substr(0,str.length-1);
$.ajax({
url:"chuli.php",
data:{str:str,type:2},
type:"POST",
dataType:"TEXT",
success: function(data){
alert(data);
XianShi();
}
});
})
}
//给查看详情加点击事件
});
</script>
</html>
<?php
include("DBDA.php");
$db = new DBDA();
$code = $_POST["code"];
$sql = "select * from Nation where Code = '{$code}'";
echo $db->StrQuery($sql);
.zhuti
{
position:absolute;
z-index:3;
font-size:14px;
border-radius:5px;
box-shadow:0 0 5px white;
overflow:hidden;
color:#333;
}
.title
{
background-color:#3498db;
vertical-align:middle;
height:35px;
width:100%;
line-height:35px;
text-indent:1em;
}
.close{
float:right;
width:35px;
height:35px;
font-weight:bold;
line-height:35px;
vertical-align:middle;
color:white;
font-size:18px;
}
.close:hover
{
cursor:pointer;
}
.content
{
text-indent:1em;
padding-top:10px;
}
.btnx
{
height:30px;
width:100%;
text-indent:1em;
}
.btn
{
height:28px;
width:80px;
float:left;
margin-left:20px;
color:#333;
}
#zz
{
width:100%;
height:100%;
opacity:0.15;
display:none;
background-color:#ccc;
z-index:2;
position:absolute;
top:0px;
left:0px;
}
<?php
include("DBDA.php");
$db = new DBDA();
$str = $_POST["str"];
$attr = explode("|",$str);
$tj = implode($attr,"','");
$sql = "delete from Nation where Code in ('{$tj}')";
if($db->Query($sql,0))
{
echo "删除成功!";
}
else
{
echo "删除失败!";
}
<?php
include("DBDA.php");
$db = new DBDA();
$type = $_POST["type"];
switch($type)
{
case 0:
$sql = "select * from Nation";
echo $db->StrQuery($sql);
break;
case 1:
$code = $_POST["code"];
$sql = "select * from Nation where Code = '{$code}'";
echo $db->StrQuery($sql);
break;
case 2:
$str = $_POST["str"];
$attr = explode("|",$str);
$tj = implode($attr,"','");
$sql = "delete from Nation where Code in ('{$tj}')";
if($db->Query($sql,0))
{
echo "删除成功!";
}
else
{
echo "删除失败!";
}
break;
default:
echo "";
}