使用了struts2的标签,怎么实现Ajax分页?
解决方案 »
- 关于项目打包!!!!
- js 缺少对象错误 求解决
- jsp在线人数统计和在线用户名的显示?
- 为什么现在还有一部人喜欢用jsp+javabean+servlet做项目架构?它与其它相比,有什么优势?
- 报表开发(请教crystal处理clob数据类型的字段)_高分求解
- 分页显示问题
- xml的utf-8一问,将String转换成xml文档为什么里面不能有中文呢?
- 不用sumbit提交,在onclick事件中提交怎么做,因为我的页面要验证完后才提交。
- <% 一段代码大家看看 %》
- 循环显示的问题:)
- spring3、struts2用注解整合的问题
- 数据库连接不上,但是数据库已经启动,而且用的连接池,用户名和密码也对,求解
<script language="javascript">
var pagecount=1;
var pages=1;
$(document).ready(function() {
$("#tb th").addClass("TableHead");
$("#tb tr").eq(2).hide();
getInfo();
});
function getInfo(){
$.ajax({
url:"product.do?fun=doQuery&userid=${userinfo.accountno}&pagecount="+pagecount,
data:null,
type:'post',
dataType:'json',
success:function(data){
addInsInfo(data);
}
});
}
function addInsInfo(data){
$("#tb1 tr:gt(0)").each(function() {
$(this).remove();
});
var tab=document.getElementById("tb1");
var num=data.list.length;
pages=data.pages;
pagecount=data.pagecount;
for(var i=0;i<num;i++){
var k=i+1;
//添加行
var newTr = tab.insertRow();
//newTr.style.backgroundColor="#cccccc";
//添加列
var newTd0 = newTr.insertCell();
var newTd1 = newTr.insertCell();
var newTd2 = newTr.insertCell();
var newTd3 = newTr.insertCell();
newTd0.className="row";
newTd1.className="row";
newTd2.className="row";
newTd3.className="row";
//设置列内容和属性
newTd0.innerText =k
newTd1.innerText =data.list[i].productname;
newTd2.innerText =data.list[i].defdate;
var innerstr=""
var modify="<input name='modify' type='button' id='modify' value='修改' onclick=\"goEdit(\'"+data.list[i].PId+"\')\">";
var del="<input name='delete' type='button' id='delete' value='删除' onclick=\"doDelete(\'"+data.list[i].PId+"\')\">";
var moban="<input name='moban' type='button' id='moban' value='模板' onclick=\"gotoPrint(\'"+data.list[i].PId+"\',\'"+data.list[i].productname+"\',\'"+data.list[i].prodtemplate+"\')\">"
newTd3.innerHTML=modify+del+moban;
}
var tab2=document.getElementById("tb2");
var rows=tab2.rows.length;
var newTr ;
var newTd0 ;
var newTd1;
if(rows>0){
newTr=tab2.rows[0];
newTd0=newTr.cells[0];
newTd1=newTr.cells[1];
}else{
newTr = tab2.insertRow();
newTd0 = newTr.insertCell();
newTd1 = newTr.insertCell();
}
newTd0.innerText ="共"+data.counts+"条/每页"+data.pagesize+"条 第"+data.pagecount+"页/共"+data.pages+"页"
var innerthml="<div align='right'>";
if(data.pagecount=='1'){
innerthml+="[首页] [上一页]";
if(data.pages=='1'){
innerthml+=" [下一页] [尾页]";
}else{
innerthml+="<a href='#' onclick='jump(\"down\")'>[下一页]</a> <a href='#' onclick='jump(\"weiye\")'>[尾页]</a>";
}
}else{
if(data.pages=='1'){
innerthml+="[首页] [上一页]";
}else{
innerthml+="<a href='#' onclick='jump(\"shouye\")'>[首页]</a> <a href='#' onclick='jump(\"up\")'>[上一页]</a>";
}
if(data.pages==data.pagecount){
innerthml+=" [下一页] [尾页]";
}else{
innerthml+="<a href='#' onclick='jump(\"down\")'>[下一页]</a> <a href='#' onclick='jump(\"weiye\")'>[尾页]</a>";
}
}
innerthml+=" 转第<select id='jumpselect' name='jumpselect' onchange=\"jump01()\">"
for(var i=1;i<=data.pages;i++){
if(pagecount==i){
innerthml+="<option value='"+i+"' selected>"+i+"</option>";
}else{
innerthml+="<option value='"+i+"' >"+i+"</option>";
}
}
innerthml+="</select>页</div";
newTd1.innerHTML=innerthml;
}
function goEdit(pid){
$.ajax({
url:"product.do?fun=findById&pid="+pid,
data:null,
type:'post',
dataType:'json',
success:function(data){
setProduct(data);
}
});
}
function setProduct(data){
if(data.PId!=null){
$("#PId").val(data.PId);
}
if(data.productid!=null){
$("#productid").val(data.productid);
}
if(data.agencyprice!=null){
$("#agencyprice").val(data.agencyprice);
}
if(data.productstate!=null){
$("#productstate").val(data.productstate);
}
if(data.attributionid!=null){
$("#attributionid").val(data.attributionid);
}
if(data.definer!=null){
$("#definer").val(data.definer);
}
if(data.CId!=null){
$("#CId").val(data.CId);
}
if(data.companyname!=null){
$("#companyname").val(data.companyname);
}
if(data.cusdefpro!=null){
$("#cusdefpro").val(data.cusdefpro);
}
if(data.protype!=null){
if(data.protype=='0'){
$("#protype").get(0).selectedIndex=0;
}else{
$("#protype").get(0).selectedIndex=1;
}
}
if(data.ordername!=null){
$("#ordername").val(data.ordername);
}
if(data.productname!=null){
$("#productname").val(data.productname);
}
if(data.prodcode!=null){
$("#prodcode").val(data.prodcode);
oldcode=data.prodcode;
}
if(data.minday!=null){
$("#minday").val(data.minday);
}
if(data.maxday!=null){
if(data.maxday=="1"){
$("#productdeftype").get(0).selectedIndex=1;
}else{
$("#productdeftype").get(0).selectedIndex=0;
}
}
$("#prodtemplate").val(data.prodtemplate);
if(data.description!=null){
$("#description").val(data.description);
}
if(data.amount!=null){
$("#amount").val(data.amount);
}
changeMinxi();
if(data.minday!=null){
$("#minday").val(data.minday);
}
if(data.maxday!=null){
$("#maxday").val(data.maxday);
}
if(data.price!=null){
$("#price").val(data.price);
}
if($("#productdeftype").val()=='0'){
if(data.accstandard=='1'){
document.getElementById("accstandard").checked=true;
}
}
fun="edit";
}
function doDelete(pid){
$.ajax({
url:"product.do?fun=doDelete&userid=${userinfo.accountno}&pid="+pid,
data:null,
type:'post',
success:function(msg){
if(msg=='0'){
alert("删除产品成功");
getInfo();
}else if(msg=='-1'){
alert("该产品已经被使用,不能删除!");
}else{
alert("删除失败");
}
}
});
}
function jump(go){
if(go=='shouye'){
pagecount=1
}else if(go=='up'){
pagecount=pagecount-1;
}else if(go=='down'){
pagecount=pagecount+1;
}else{
pagecount=pages;
}
getInfo();
}
function jump01(){
pagecount=document.getElementById("jumpselect").value;
getInfo();
}
function gotoPrint(ID, PrdNm,temp)
{
var tem=document.getElementById("tem");
tem.style.position="absolute";
tem.style.right=150;
tem.style.top=13;
tem.style.zIndex=0;
tem.style.background="#ffffff";
tem.style.display="";
if(temp!='null'){
$("#temp").val(temp);
}
$("#id").val(ID);
$("#name").val(PrdNm);
}
</script>
</head>
<body>
<table width="60%" align="center" border=1 cellspacing=0
bordercolorlight=#33AECC bordercolordark=#efefef id="tb1">
<caption>
产品列表
</caption>
<thead>
<tr bgcolor=#33AECC>
<th width="35" nowrap scope="col">
No.
</th>
<th width="200" nowrap scope="col">
产品名称
</th>
<th width="100" nowrap scope="col">
添加时间
</th>
<th width="132" nowrap scope="col">
操作
</th>
</tr>
</thead>
</table>
<table width="60%" align="center" border=1 cellspacing=0
bordercolorlight=#44bbbb bordercolordark=#efefef id="tb2">
</table>
</body>
<form name="form1" action="">
</form>
</html>