<!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>javascript
在使用bootstrap和jQuery前須要引入這三個文件
<link href="dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="../jquery/jquery-1.11.2.min.js"></script>
<script src="dist/js/bootstrap.min.js"></script>
<style type="text/css">
.xq{ margin-left:5px}
</style>
</head>php
<body>
<h1>顯示數據</h1>css
<table class="table table-striped">
<thead>
<tr>
<th width="30%">代號</th>
<th width="30%">名稱</th>
<th width="40%">操做</th>
</tr>
</thead>
<tbody id="tb">
</tbody>
</table>html
<!--模態框-->
<!-- 模態框(Modal) -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">詳細信息</h4>
</div>
<div class="modal-body" id="nr">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">關閉</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>java
</body>
<script type="text/javascript">jquery
加載數據
Load();ajax
加載數據的方法
function Load()
{
$.ajax({
url:"jiazai.php",
dataType:"TEXT",
success: function(data){
var str = "";
var hang = data.split("|");
for(var i=0;i<hang.length;i++)
{
var lie = hang[i].split("^");
str = str+"<tr><td>"+lie[0]+"</td><td>"+lie[1]+"</td><td><button type='button' class='btn btn-info btn-sm sc' code='"+lie[0]+"'>刪除</button><button type='button' class='btn btn-primary btn-sm xq' code='"+lie[0]+"'>查看詳情</button></td></tr>";
}
$("#tb").html(str);
addshanchu();
addxiangqing();
}
});
}bootstrap
給刪除按鈕加事件的方法
function addshanchu()
{
刪除事件
$(".sc").click(function(){
var code = $(this).attr("code");
$.ajax({
url:"shanchu.php",
data:{code:code},
dataType:"TEXT",
type:"POST",
success: function(d){
if(d.trim()=="OK")
{
alert("刪除成功");
Load();
}
else
{
alert("刪除失敗");
}
}
});
})
}ui
給查看詳情加事件的方法
function addxiangqing()
{
$(".xq").click(function(){
顯示模態框
$('#myModal').modal('show');
在模態框裏面顯示內容
var code = $(this).attr("code");
$.ajax({
url:"xiangqing.php",
data:{code:code},
dataType:"TEXT",
type:"POST",
success:function(data){
var lie = data.split("^");
var str = "<div>民族代號:"+lie[0]+"</div><div>民族名稱:"+lie[1]+"</div>";
$("#nr").html(str);
}
});
})
}
</script>
</html>this