<!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=gb2312" />
<title>蓝光-BlueShine</title>
<script language="JavaScript">
var Count=false,NO=-1;
function addRow(){
Count=!Count;
//添加一行
var newTr = new Array(20);
for(var i=0;i<20;i++)
{newTr[i] = testTbl.insertRow(testTbl.rows.length);//添加两列
//alert("add");
var newTd0 = newTr[i].insertCell();var newTd1 = newTr[i].insertCell();
var newTd2 = newTr[i].insertCell();
var newTd3 = newTr[i].insertCell();
//设置列内容和属性
if(Count)
{
newTr[i].style.background="#FFE1FE";
}else
{
newTr[i].style.background="#FFEFDF";
}
newTd0.innerHTML = "2013-09-09 10:10";
newTd1.innerHTML = "电表通讯故障";
NO++;
newTd2.innerText="第"+ NO +"行";
}}
</script></head>
<body>
<table align="center" width="399" border=0 cellspacing="1" id="testTbl" style="font-size:14px;">
<tr bgcolor="#FFEFD5">
<td width=6%> </td>
<td >序号</td>
<td > 设备</td>
<td > 时间</td></tr>
</table><label>
<input type="button" value="插入行" onclick="addRow()"/>
</label>
</body>
</html>
问题: 上面的代码只是个简单的插入实现,现在我想要的功能是:三个按钮:1、查询 2、下一页 3、上一页 的每一页显示20个事件记录,事件记录总共不多,总共256个,请问大神们,怎么实现,可以在这个代码里修改,加入事件记录data数据已经通过ajax获取到了,
谢谢了、、、javascripthtml故障通讯
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function createData(){
var a={};
for(var i=0;i<256;i++){
a[i+".name"]=i+"name";
a[i+".age"]=i+'age';
a[i+".sex"]=((i&1)==0?'男':'女');
}
return a;
}
function createTable(){
for(var i=0;i<=19;i++){
var tr=document.createElement("tr");
for(var j=0;j<=2;j++){
tr.appendChild(document.createElement("td"));
}
document.getElementById("data").appendChild(tr);
}
}
function findData(x,data){
var tds=document.getElementsByTagName("td");
var j=0;
for(var i=(x-1)*20;i<x*20;i++){
tds[j++].innerHTML=data[i+'.name'];
tds[j++].innerHTML=data[i+'.age'];
tds[j++].innerHTML=data[i+'.sex'];
}
}
window.onload=function(){
var data=createData();
var isInit=false;
var f=document.getElementById("find");
var p=document.getElementById("page");
var n=document.getElementById("next");
var r=document.getElementById("pre");
f.onclick=function(){
if(!isInit){
createTable();
p.value=1;
isInit=true;
}
findData(p.value,data);
}
r.onclick=function(){
if(!isInit){
createTable();
p.value=1;
isInit=true;
}else{
p.value=parseInt(p.value)-1;
}
findData(p.value,data);
}
n.onclick=function(){
if(!isInit){
createTable();
isInit=true;
p.value=1;
}else{
p.value=parseInt(p.value)+1;
}
findData(p.value,data);
}
}
</script>
</head><body>
<div id="test">
<table>
<tbody id="data">
<tr>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
</tr>
</tbody>
</table>
</div>
<input type="button" value="查询" id="find" />
<input type="button" value="上一页" id="pre" />
<input type="button" value="下一页" id="next" />
当前页<input type="text" value="" id="page">
</body>
</html>
类似这样试试 没对页数的范围做判断
可以用jquery easy ui或者ext js的datagrid
那个非常强大
也可以啊,能说说怎么弄吗,是不是药用到jquery里面的摸个控件来显示呢
也可以啊,能说说怎么弄吗,是不是药用到jquery里面的摸个控件来显示呢我觉得就用AJAX到后台查询数据,,转成json。到前台用遍历输出。完了
var tb=$("#tbStu").empty();
$("<tr> <th >用户全名 </th><th>用户手机号</th><th>用户单位</th><th>用户部门</th><th>系统类型</th><th>请求时间</th><th>操作类型</th></tr>").appendTo(tb);
$.ajax({
type:'post',
url:'getJson.action',
dataType:'html',
async: false,
success:function(msg){
var s=eval(msg);
$(s).each(function(key,val){
tr=$("<tr></tr>");
$("<td onclick=\"openwindow('loadMoLogInfo.action?pid="+val.pid+"','',1000,600);\">"+val.username+"</td>").appendTo(tr);
$("<td onclick=\"openwindow('loadMoLogInfo.action?pid="+val.pid+"','',1000,600);\">"+val.mobile+"</td>").appendTo(tr);
$("<td onclick=\"openwindow('loadMoLogInfo.action?pid="+val.pid+"','',1000,600);\">"+val.cpname+"</td>").appendTo(tr);
$("<td onclick=\"openwindow('loadMoLogInfo.action?pid="+val.pid+"','',1000,600);\">"+val.depname+"</td>").appendTo(tr);
$("<td onclick=\"openwindow('loadMoLogInfo.action?pid="+val.pid+"','',1000,600);\">"+val.system+"</td>").appendTo(tr);
$("<td onclick=\"openwindow('loadMoLogInfo.action?pid="+val.pid+"','',1000,600);\">"+val.reqtime+"</td>").appendTo(tr);
$("<td onclick=\"openwindow('loadMoLogInfo.action?pid="+val.pid+"','',1000,600);\" >"+val.typecode+"</td> ").appendTo(tr);
tr.appendTo("#tbStu")
});
}
});
$("#tbStu tr:nth-child(odd)").css("background-color","#fff");
$("#tbStu tr").hover( function(){$(this).css("background-image","url(../common/style/blue/images/table_title_bg.png)");},
function(){$(this).css("background-image","");});
}
也可以啊,能说说怎么弄吗,是不是药用到jquery里面的摸个控件来显示呢我觉得就用AJAX到后台查询数据,,转成json。到前台用遍历输出。完了现在是数据获取到了,就是显示的问题,现在是一次查询到的数据总共256个,你要是依=一次全部显示在界面上的话,有点不好看,想做成上一页,下一页的这种显示