标签:
需求:
主界面代码:
<!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" /> <script src="jquery-2.2.3.js"></script> <script src="tanchuang.js"></script> <title>无标题文档</title> <link href="tanchuang.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>测试</h1> <?php //显示所有数据 include ("database.class.php"); $db = new database(); $sql = "select * from Info"; $attr = $db->Query($sql); echo "<table width=‘100%‘ cellpadding=‘0‘ cellspacing=‘0‘ border=‘1‘> <tr><td>代号</td><td>姓名</td><td>性别</td><td>民族</td><td>生日</td><td>操作</td></tr> "; foreach ($attr as $v) { echo "<tr><td><input type=‘checkbox‘ class=‘xx‘ value=‘{$v[0]}‘/>{$v[0]}</td><td>{$v[1]}</td><td>{$v[2]}</td><td>{$v[3]}</td><td>{$v[4]}</td><td><input type=‘button‘ class=‘xq‘ bs=‘{$v[0]}‘ value=‘查看详情‘/></td></tr>"; } echo "<tr><td colspan=‘6‘><input type=‘checkbox‘ id=‘qx‘/>全选 <input type=‘button‘ value=‘批量删除‘ id=‘sc‘/></td></tr>"; echo "</table>"; ?> </body> </html> <script> $(document).ready(function(e) { //全选功能 $("#qx").click(function () { var qx = $(this)[0].checked; var xx = $(".xx"); for(var i = 0;i<xx.length;i++) { xx[i].checked = qx; } }) //批量删除 $("#sc").click(function () { var xx = $(".xx"); for(var i =0;i<xx.length;i++) { if(xx.eq(i).prop("checked")) { var code = xx.eq(i).val(); //alert(code); } } //调用Ajax $.ajax({ url:"Delete.php", data:{code:code}, dataType:"TEXT", type:"POST", success: function(d) { if(d=="OK") { alert("删除成功"); window.location="main.php"; } else { alert("删除失败"); window.location="main.php"; } } }) }) //查看详情 $(".xq").click(function () { var v = $(this).attr("bs"); //获取bs属性(也就是获取主键值) //alert(v); $.ajax({ url:"xqcl.php", data:{v:v}, type:"POST", dataType:"TEXT", success: function(d) { if(d!="") { var hang = d.split("|"); for(var i = 0 ;i<hang.length;i++) { var lie = hang[i].split("^"); } var html = "代号:‘"+lie[0]+"‘,姓名:‘"+lie[1]+"‘,性别:‘"+lie[2]+"‘,民族:‘"+lie[3]+"‘,生日:‘"+lie[4]+"‘"; var button ="<input type=‘button‘ value=‘确定‘/> <input type=‘button‘ value=‘取消‘/>"; var win = new Window({ width:700, height:400, title:‘详情‘, content:html, isMask:false, buttons:button, isDrag:true, }) } } }) }) }); </script>
删除界面代码:
<?php $code = $_POST["code"]; include ("database.class.php"); $db = new database(); $sql = "delete from Info where Code=‘{$code}‘"; $result = $db->Query($sql,1); if($result) { echo "OK"; } else { echo "NO"; }
详情页面代码:
<?php $v = $_POST["v"]; include ("database.class.php"); $db = new database(); $sql = "select * from Info where Code=‘{$v}‘"; $result = $db->str_ajax($sql); echo $result;
总结:
标签:
原文地址:http://www.cnblogs.com/Itwonderful/p/5513622.html