网页:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
< html>
< head>
<title>查验表</title>
<meta http-equiv="keywords" content="监测线">
<meta http-equiv="description" content="监测线">
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/remote.css">
<script type="text/javascript" src="../script/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/remote.js"></script>
< /head>
< body>
< div class="query">
< fieldset class="query">
< span class="tip">所有人:</span><input type="text" class="txt" title="按Enter键查询" id="query_user">
< span class="tip">VIN:</span><input type="text" class="txt" title="按Enter键查询" id="query_vin">
< span class="tip">发动机型号:</span><input type="text" class="txt" title="按Enter键查询" id="query_enery">
< span class="tip">号牌号码:</span><input type="text" class="txt" id="query_num">
< input type="button" class="bts" value="清空" title="点击清空参数" onclick="blankArgs();">
< input type="button" class="bts" value="查询" title="点击执行查询" onclick="getDataList();">
< /fieldset>
< /div>
< !--------------------------------------------end 查询div---------------------------------------------------->
<table class="data" cellspacing="0px" cellpadding="0px" id="tabList">
< tr>
< th><input type="checkbox" id="checkall" onclick="selectAll(this);"></th>
< th>流水号</th>
< th>号牌种类</th>
< th>号牌号码</th>
< th>所有人</th>
< th>车辆识别号</th>
< th>发动机号</th>
< th>车身颜色</th>
< th>查验状态</th>
< th>查验员</th>
< th>查验时间</th>
< th style="border-right:1px #00FFFF solid;">操作</th>
< /tr>
< /table>
< !--------------------------------------------end 数据列表---------------------------------------------------->
<div class="page">
< input type="button" class="bts" value="删除选中项" onclick="delSeledRecord();">
< span class="tip" id="pageinfo">当前页:第0/0页</span>
< img src="imgs/page/first.gif" class="page" alt="首页" onclick="setPage(1);">
< img src="imgs/page/prev.gif" class="page" alt="上一页" onclick="setPage(2);">
< img src="imgs/page/next.gif" class="page" alt="下一页" onclick="setPage(3);">
< img src="imgs/page/last.gif" class="page" alt="尾页" onclick="setPage(4);">
< input type="text" class="txt" style="width:40px;" value="0" title="按Enter键跳页"
id="jumppage" onkeyup="this.value=this.value.replace(/\D/g,'');">
< input type="button" class="bts" value="翻页" onclick="jumpPage();">
< /div>
< !--------------------------------------------end 分页div---------------------------------------------------->
< /body>
< /html>
样式文件:
@CHARSET "UTF-8";
body{
margin:0px;
padding:10px;
background-color:#FFFFFF;
font-size:12px;
}
fieldset{
margin:0px 0px 0px 20px;
padding:5px;
width:95%;
border:1px #FFCCFF solid;
}
input.bts{
margin:0px 0px 0px 5xp;
padding:2px 3px 1px 3px;
background-color:#66CCFF;
border:1px #000000 solid;
font-size:11px;
color:#FFFFFF;
}
img.page{
margin:0px;
padding:0px;
width:12px;
height:12px;
border:none;
}
span.tip{
margin:0px 3px 0px 5px;
padding:0px;
}
div.query{
margin:0px;
padding:5px;
width:100%;
background-color:#F0FFFF;
text-align:left;
overflow:auto;
}
div.page{
margin:0px;
padding:3px 2px 2px 2px;
width:100%;
background-color:#F0FFFF;
border:1px #CCCCCC solid;
vertical-align:bottom;
overflow:hidden;
}
table{
margin:0px;
padding:0px;
border:none;
}
table.data{
width:100%;
border:none;
overflow:auto;
}
th{
margin:0px;
padding:0px;
background-color:#AFEEEE;
border-top:1px #00FFFF solid;
border-right:none;
border-bottom:1px #00FFFF solid;
border-left:1px #00FFFF solid;
font-size:13px;
text-align:center;
vertical-align:middle;
}
td{
padding:0px;
margin:0px;
border:none;
border-right:1px #CCCCCC dotted;
border-bottom:1px #CCCCCC dotted;
font-size:12px;
text-align:center;
vertical-align:middle;
overflow:hidden;
}
/*以下样式被脚本调用*/
input.txt{
padding:1px 0px 1px 2px;
width:140px;
border:1px solid #87C6F9;
border-radius:6px;
}
input.txtfocus{
padding:1px 0px 1px 2px;
width:140px;
border:1px #00FFFF solid;
box-shadow:0px 0px 8px rgba(103, 166, 217, 1);
outline:none;
}
tr.ou{
background-color:"#EEEEFF";
}
tr.qi{
background-color:"#FFFFFF";
}
tr.hover{
background-color:#FFCCFF;
}
分页图片:
脚本:
//所有记录
var allRecord=null;
//记录数
var allCount=0;
//每页记录数
var pageSize=10;
//总页数
var pageCount=0;
//当前页
var currPage=1;
//Enter键监听
$(document).ready(function(){
var $inp=$("input:text");
$inp.keypress(function(e){
if(!e){
e=window.event;
}
if(e.which==13){
if(this.id=="jumppage"){
jumpPage();
}else{
getDataList();
}
}
});
var oldcss="";
$inp.focus(function(){
oldcss=$(this).attr("class");
$(this).removeClass(oldcss).addClass("txtfocus");
});
$inp.blur(function(){
$(this).removeClass("txtfocus").addClass(oldcss);
});
$inp[0].focus();
});
//清空查询参数
function blankArgs(){
$("#query_user").val("");
$("#query_vin").val("");
$("#query_enery").val("");
$("#query_num").val("");
}
//清空数据表
function blankList(){
var trLen=$("#tabList").find("tr").length;
for(var i=trLen;i>0;i--){
$("#tabList").find("tr").eq(i).remove();
}
}
//执行查询
function getDataList(){
allRecord=null;
blankList();
//添加aJax请求后台数据的代码,allRecord最好是JSON数组,这样解析数据容易
allRecord=new Object();
allCount=56;
if(allCount%pageSize==0){
pageCount=allCount/pageSize;
}else{
pageCount=parseInt(allCount/pageSize)+1
}
//显示第一页数据
currPage=-1;
setPage(1);
}
//分页
function setPage(type){
if(!allRecord){
window.alert("没有数据");
return;
}
if(pageCount<=1){
window.alert("总页数不够");
return;
}
if(currPage==1&&type==1){
window.alert("已是首页");
return;
}
if(currPage==1&&type==2){
window.alert("已是第一页");
return;
}
if(currPage==pageCount&&type==3){
window.alert("已是最后一页");
return;
}
if(currPage==pageCount&&type==4){
window.alert("已是尾页");
return;
}
var start=0;
var end=0;
if(type==1){
currPage=1;
start=0;
end=pageSize;
}else if(type==2){
currPage--;
start=(currPage-1)*pageSize;
end=currPage*pageSize;
}else if(type==3){
currPage++;
start=(currPage-1)*pageSize;
end=Math.min(currPage*pageSize,allCount);
}else if(type==4){
currPage=pageCount;
start=(currPage-1)*pageSize;
end=allCount;
}
blankList();
//向表格写入数据
for(var i=start;i<end;i++){
var id=i;
var bgcss=" ";
if(i%2==0){
bgcss=" class='ou'";
}else if(i%2==1){
bgcss=" class='qi'";
}
var strHtml="<tr name='datarow' "+bgcss+">";
strHtml+="<td><input type='checkbox' name='item' value='"+id+"' id='"+id+"'></td>";
strHtml+="<td>"+i+"</td>";
strHtml+="<td>小型汽车</td>";
strHtml+="<td>京A12033</td>";
strHtml+="<td>张飞</td>";
strHtml+="<td>LSYBCAAF38K019621</td>";
strHtml+="<td>016355</td>";
strHtml+="<td>蓝色</td>";
strHtml+="<td>通过</td>";
strHtml+="<td>李四</td>";
strHtml+="<td>2012-12-16</td>";
strHtml+="<td><a href=javascript:preView('"+id+"');>查看照片</a> ";
strHtml+="<a href=javascript:delSingleRecord('"+id+"');>删除</a> ";
strHtml+="<a href=javascript:getDetail('"+id+"');>详细</a></td>";
strHtml+="</tr>";
$("#tabList").append(strHtml);
}
var oldcss=null;
$("tr[name='datarow']").hover(
function(){
oldcss=$(this).attr("class");
$(this).removeClass(oldcss).addClass("hover");
},
function(){
$(this).removeClass("hover").addClass(oldcss);
}
);
$("#checkall").removeAttr("checked");
$("#pageinfo").html("当前页:第"+currPage+"/"+pageCount+"页");
$("#jumppage").val(currPage);
}
//跳转分页
function jumpPage(){
var page=parseInt($("#jumppage").val());
if(!allRecord){
$("#jumppage").val(0);
window.alert("没有数据");
return;
}
if(page<1||page>pageCount){
$("#jumppage").val(currPage);
window.alert("输入的页数不对");
return;
}
if(page==currPage){
return;
}
if(page==1){
currPage=-1;
setPage(1);
}else if(page==pageCount){
currPage=-1;
setPage(4);
}else{
currPage=page-1;
setPage(3);
}
}
//全选或全不选
function selectAll(obj){
$("input:checkbox[name='item']").each(function(i){
$(this).attr("checked",obj.checked);
});
}
//查看照片
function preView(id){
window.alert("查看照片 "+id);
}
//删除单个记录记录
function delSingleRecord(id){
$("#"+id).attr("checked",true);
delAct(1,id);
}
//删除选中的所有记录
function delSeledRecord(){
delAct(2,null);
}
//执行删除
function delAct(type,id){
if(!allRecord){
window.alert("没有数据");
return;
}
var args="";
if(type==1&&id!=null){
args=id;
}else if(type==2){
var objDels=$("input[name='item']:checked");
objDels.each(function(i){
args+=$(this).val()+",";
});
args=args.substring(0,args.length-1);
}else{
return;
}
if(args==""){
window.alert("还没进行选择");
return;
}
if(!window.confirm("确认删除被选记录吗")){
return;
}
args="?type=del&dels="+agrs;
$.ajax({
type:"POST",
processData:true,
url:"../servlet/TestServlet",
data:agrs,
success:function(msg){
if($.trim(msg.result)=="succ"){
window.alert("删除成功");
}else{
window.alert("删除失败");
}
}
});
}
//查看详细
function getDetail(id){
window.alert("查看详细 "+id);
}
效果预览: