ajax實(shí)現(xiàn)加載頁面、刪除、查看詳細(xì)信息 bootstrap美化頁面!
由于有些的程序員可能不是很會Photoshop,所以為了美化頁面,我們可以借助工具bootstrap,實(shí)現(xiàn)起來相對就要比之前做的美觀一些,
今天我用bootstrap把之前做的顯示表格進(jìn)行了一下美化,同時(shí)也把a(bǔ)jax部分進(jìn)行了優(yōu)化,看起來會更清晰
我沒有下載bootstrap的包,直接從網(wǎng)頁引用的
<script src="jquery-3.1.1.min.js"></script> <link rel="stylesheet" > <script src="https://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
注意:如果要引用其中一個(gè)包含jquery的多個(gè)JS文件,那么jquery文件一定要放在第一位
下面是我在首頁把顯示的表格進(jìn)行了美化,用了條紋表格,相對來說更美觀了
<h2>內(nèi)容加載</h2> <table class="table table-striped"> <!--從bootstrap中引用了里面的class--> <thead> <tr> <th>水果名稱</th> <th>水果價(jià)格</th> <th>水果產(chǎn)地</th> <th>操作</th> </tr> </thead> <tbody id="tb"> </tbody> </table>
昨天寫的ajax 部分也進(jìn)行了優(yōu)化,以防太多的括號之類的出現(xiàn)問題導(dǎo)致程序不運(yùn)行,昨天的jiazaiym.php,shanchu.php已經(jīng)寫過了,今天再補(bǔ)上查看頁面xiangqing.php
<?php
header("Content-type:text/html;charset=utf-8");
$ids=$_POST["ids"];
include("DADB.class.php");
$db=new DADB();
$sql="select * from fruit where ids='{$ids}' ";
$arr=$db->Query($sql,1);
$str="";
foreach($arr as $v)
{
$str=$str.implode("^",$v)."|"; //每一行之間用“|”連接,這樣最后就會多出一個(gè)“|”
}
$str=substr($str,0,strlen($str)-1); //把最后多出的“|”用截取字符串的方式刪去
echo $str;
?>
ajax部分代碼如下:
<script type="text/javascript">
Load();
function Load() {
$.ajax({
url: "jiazaiym.php",
dataType: "TEXT",
success: function (data) {
//alert(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[1] + "</td><td>"
+ lie[2] + "</td><td>" + lie[3] + "</td><td> <button type='button' ids='"+lie[0]+"' class='btn btn-primary sc'>刪除</button><button type='button' ids='"+lie[0]+"' class='btn btn-primary ck' data-toggle='modal' data-target='#myModal'>查看</button></td></tr>" //用bootstrp寫刪除和查看的按鈕
}
$("#tb").html(str);
addshanchu();
chakan();
}
})
}
//刪除頁面的方法
function addshanchu(){
$(".sc").click(function() {
var ids = $(this).attr("ids");
$.ajax({
url: "shanchu.php",
data: {ids:ids},
type: "POST",
dataType: "TEXT",
success: function (aa) { //去空格
if (aa.trim() == "OK") {
alert("刪除成功");
Load();
}
else {
alert("刪除失敗");
}
}
})
})
}
//查看的方法:
function chakan()
{
$(".ck").click(function(){
//顯示模態(tài)框
// $('#myModal').modal('show');
//往模態(tài)框里面加內(nèi)容
var ids =$(this).attr("ids");
$.ajax({
url:"xiangqing.php",
data:{ids:ids},
type:"POST",
dataType:"TEXT",
success:function(chakan)
{
var lie=chakan.split("^");
var aa="<div>水果名稱:"+lie[1]+"</div><div>水果價(jià)格:"+lie[2]+"</div><div>水果產(chǎn)地:"+lie[3]+"</div>";
$("#nr").html(aa);
}
})
})
}
模態(tài)框的html代碼如下所示,點(diǎn)擊查看會蹦出模態(tài)框:
<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">詳細(xì)信息</h4>
</div>
<div class="modal-body" id="nr">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">關(guān)閉</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>
寫完后頁面如下所示:


這樣看起來頁面就美觀多了,而且代碼用不同的方法封裝后也顯得整齊有序了。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript通過prototype給對象定義屬性用法實(shí)例
這篇文章主要介紹了JavaScript通過prototype給對象定義屬性用法,實(shí)例分析了prototype的功能及使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03
JS實(shí)現(xiàn)在Repeater控件中創(chuàng)建可隱藏區(qū)域的代碼
在WEB應(yīng)用中,如何才能使應(yīng)用高效率呢?如何才能吸引用戶呢?這的確是個(gè)大學(xué)問,頁面的內(nèi)容,色搭配等都十分重要。但不可忽視的是,多數(shù)情況下,對于數(shù)據(jù)的呈現(xiàn)方式也是十分重要的。2010-09-09
給所有的超級練級都加上onmousemove時(shí)間的js代碼
給所有的超級練級都加上onmousemove時(shí)間的js代碼...2007-08-08
當(dāng)鼠標(biāo)移出灰色區(qū)域時(shí)候,菜單項(xiàng)怎么隱藏起來
當(dāng)鼠標(biāo)移出灰色區(qū)域時(shí)候,菜單項(xiàng)怎么隱藏起來...2007-11-11
基于PHP pthreads實(shí)現(xiàn)多線程代碼實(shí)例
這篇文章主要介紹了基于PHP pthreads實(shí)現(xiàn)多線程代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-06-06

