最近在做一个项目在表现层用的是displaytag来呈现,客户试用过后要求添加跳转指定页的功能,经过研究,用比较简单的方法实现了。
在displaytag_zh_CN.properties配置文件中,把paging.banner.full、paging.banner.first、paging.banner.last修改为:
paging.banner.full=<span
class=
"pagelinks"><input name=
"tz" id=
"tz" size=
"3" type=
"text" value=
"{5}"/>/{6}页 <button onClick=
"displaytagURL()" >跳转</button>[<a href=
"{1}">首页</a>/<a href=
"{2}">上页</a>]{0}[<a href=
"{3}">下页</a>/<a href=
"{4}">尾页</a>]<input id=
"hd" name=
"hd" type=
"hidden" value=
"{1}"/><input id=
"totalPageNum" name=
"totalPageNum" type=
"hidden" value=
"{6}"/></span>
paging.banner.first=<span class= "pagelinks"><input name= "tz" id= "tz" size= "3" type= "text" value= "{5}"/>/{6}页 <button onClick= "displaytagURL()" >跳转</button>[首页/上页] {0}[<a href= "{3}">下页</a>/<a href= "{4}">尾页</a>]<input id= "hd" name= "hd" type= "hidden" value= "{1}"/><input id= "totalPageNum" name= "totalPageNum" type= "hidden" value= "{6}"/></span>
paging.banner.last=<span class= "pagelinks"><input name= "tz" id= "tz" size= "3" type= "text" value= "{5}"/>/{6}页 <button onClick= "displaytagURL()" >跳转</button>[<a href= "{1}">首页</a>/<a href= "{2}">上页</a>]{0} [下页/尾页]<input id= "hd" name= "hd" type= "hidden" value= "{1}"/><input id= "totalPageNum" name= "totalPageNum" type= "hidden" value= "{6}"/></span>
paging.banner.first=<span class= "pagelinks"><input name= "tz" id= "tz" size= "3" type= "text" value= "{5}"/>/{6}页 <button onClick= "displaytagURL()" >跳转</button>[首页/上页] {0}[<a href= "{3}">下页</a>/<a href= "{4}">尾页</a>]<input id= "hd" name= "hd" type= "hidden" value= "{1}"/><input id= "totalPageNum" name= "totalPageNum" type= "hidden" value= "{6}"/></span>
paging.banner.last=<span class= "pagelinks"><input name= "tz" id= "tz" size= "3" type= "text" value= "{5}"/>/{6}页 <button onClick= "displaytagURL()" >跳转</button>[<a href= "{1}">首页</a>/<a href= "{2}">上页</a>]{0} [下页/尾页]<input id= "hd" name= "hd" type= "hidden" value= "{1}"/><input id= "totalPageNum" name= "totalPageNum" type= "hidden" value= "{6}"/></span>
上面的displaytagURL()方法
function displaytagURL()
{
var arrayOf_table_Tag = document.getElementsByTagName('table');
for ( var i=0; i<arrayOf_table_Tag.length; i++)
{
if(arrayOf_table_Tag[i].id.indexOf('cs')==0&&endWith(arrayOf_table_Tag[i].id,'List')) //form的名字,这里是我的项目中的命名规则,csXXXXList,这里要按照你的项目的命名规则来修改
{
var charArray = "x-"+arrayOf_table_Tag[i].id;
var checkSum = 17;
for( var j = 0; j < charArray.length; j++)
{
checkSum = 3 * checkSum + charArray.charCodeAt(j);
}
checkSum &=8388607; //对form的名字的转换,这里可以在displaytag源码中看到
var parameterIdentifier = "d-" + checkSum + "-p=";
var arrayOf_a_Tag = document.getElementsByTagName('a');
for ( var k=0; k<arrayOf_a_Tag.length; k++){
if(arrayOf_a_Tag[k].title.indexOf('转到第')==0)
{
var url = arrayOf_a_Tag[k].href;
var splitUrl = url.split( "&");
for( var l=0;l<splitUrl.length;l++)
{
if(splitUrl[l].indexOf(parameterIdentifier)!=-1)
{
if(l==0)
{splitUrl[l]= "?"+parameterIdentifier+document.getElementById('tz').value;}
else
{splitUrl[l]=parameterIdentifier+document.getElementById('tz').value;}
}
}
var realURL ='';
for(m=0;m<splitUrl.length;m++)
{
if(m!=splitUrl.length-1)
{realURL+=splitUrl[m]+'&';}
else
{realURL+=splitUrl[m];}
}
window.location=realURL;
break;
return;
}
}
}
}
}
{
var arrayOf_table_Tag = document.getElementsByTagName('table');
for ( var i=0; i<arrayOf_table_Tag.length; i++)
{
if(arrayOf_table_Tag[i].id.indexOf('cs')==0&&endWith(arrayOf_table_Tag[i].id,'List')) //form的名字,这里是我的项目中的命名规则,csXXXXList,这里要按照你的项目的命名规则来修改
{
var charArray = "x-"+arrayOf_table_Tag[i].id;
var checkSum = 17;
for( var j = 0; j < charArray.length; j++)
{
checkSum = 3 * checkSum + charArray.charCodeAt(j);
}
checkSum &=8388607; //对form的名字的转换,这里可以在displaytag源码中看到
var parameterIdentifier = "d-" + checkSum + "-p=";
var arrayOf_a_Tag = document.getElementsByTagName('a');
for ( var k=0; k<arrayOf_a_Tag.length; k++){
if(arrayOf_a_Tag[k].title.indexOf('转到第')==0)
{
var url = arrayOf_a_Tag[k].href;
var splitUrl = url.split( "&");
for( var l=0;l<splitUrl.length;l++)
{
if(splitUrl[l].indexOf(parameterIdentifier)!=-1)
{
if(l==0)
{splitUrl[l]= "?"+parameterIdentifier+document.getElementById('tz').value;}
else
{splitUrl[l]=parameterIdentifier+document.getElementById('tz').value;}
}
}
var realURL ='';
for(m=0;m<splitUrl.length;m++)
{
if(m!=splitUrl.length-1)
{realURL+=splitUrl[m]+'&';}
else
{realURL+=splitUrl[m];}
}
window.location=realURL;
break;
return;
}
}
}
}
}
原理是很简单的,就是修改系统的URL,不明白的地方可以联系我。
转载于:https://blog.51cto.com/li5hong/267260