“上页 下页 选择的页数:第 页 GO“这段JSP代码如何写:选择的页数:第 页 GO
当前页数:[1/4] 下一页 尾页 特别是输入页数的这段
当前页数:[1/4] 下一页 尾页 特别是输入页数的这段
答案:这个一般用javascript来写的 我给你一段我们练习的时候的代码给你,输入多少页在input的text文本框内做一个丢失焦点事件onblur="forward(this);" 然后用Javascript做一个函数,获得this.value就可以得到用户输入的多少页了.当然你也可以做一些数据格式效验,安全检测这些的,
<html>
<head>
<title>神马大作战</title>
<script type="text/javascript" >
function begin(){
if(${param.pageIdx}<=1){
document.getElementById("pre").disabled=true;
}
if(${param.pageIdx}>=2){
document.getElementById("next").disabled=true;
}
}
function prev(){
window.location="/bank/queryAccountByPageIdx?pageIdx="+${param.pageIdx-1};
}
function next(){
window.location="/bank/queryAccountByPageIdx?pageIdx="+${param.pageIdx+1};
}
function sall(){
var checkBoxs = document.getElementsByTagName("input");
for(idx in checkBoxs){
if(checkBoxs[idx].type=="checkbox"){
checkBoxs[idx].checked="checked";
}
}
}
function del(){
var save="";
var checkBoxs = document.getElementsByTagName("input");
for(idx in checkBoxs){
if((checkBoxs[idx].type=="checkbox")&&(checkBoxs[idx].checked="checked")){
save += checkBoxs[idx].value+",";
}
}
window.location="/bank/queryAccountByPageIdx?pageIdx="+${param.pageIdx}+"&save="+save;
}
</script>
</head>
<body onload="begin();">
<div style="margin-left: 70">共${sum }页 第${param.pageIdx}页
<input type="button" id="pre" value="上一页" onclick="prev();" />
<input type="button" id="next" value="下一页" onclick="next();"/>
</div>
<cq:loopView pageSize="10" pageIdx="${param.pageIdx}"/>
<div style="margin-left: 70">
<input type="button" id="sall" value="全选" onclick="sall();" />
<input type="button" id="del" value="删除" onclick="del();"/>
</div>
</body>
</html>
我自己写了一个简易的tag也给你吧,你如果不要可以直接用jstl也可以,稍微改一下就可以了
public class LoopViewTag implements SimpleTag{
private JspTag jspTag;
private JspContext jspContext;
private int pageSize;
private int pageIdx;
private JspFragment jf;
/**
* <loopTag pageIdx=? pageSize=? /> || <loopTag pageIdx=? pageSize=? tableName=? />
*/
public void doTag() throws JspException, IOException {
AccountService accountService = new AccountServiceImpl();
List<Account> as = accountService.QueryAccountByPageidx(pageIdx, pageSize);
JspWriter out = jspContext.getOut();
out.print("<center><table border=1 cellspacing='0' width='920' cellspacing='0' cellspadding='0' style='border-style: solid'>");
out.print("<tr height='20' bgcolor='gray'>");
out.print("<td width='20'></td><td width='100'>用户</td><td width='100'>密码</td><td width='100'>卡号</td><td width='100'>余额</td><td width='200'>注册时间</td><td width='100'>电话</td><td width='200'>所在地</td></tr>");
for (Account account : as) {
out.print("<tr height='20'>");
out.print("<td>");
out.print("<input type='checkbox' value='"+account.getName()+"'/>");
out.print("</td>");
out.print("<td>");
out.print(account.getName());
out.print("</td>");
out.print("<td>");
out.print(account.getPwd());
out.print("</td>");
out.print("<td>");
out.print(account.getCardId());
out.print("</td>");
out.print("<td>");
out.print(account.getMoney());
out.print("</td>");
out.print("<td>");
out.print(account.getRegTime());
out.print("</td>");
out.print("<td>");
out.print(account.getPhone());
out.print("</td>");
out.print("<td>");
out.print(account.getAddress());
out.print("</td>");
out.print("</tr>");
}
out.print("</table></center>");
}
public JspTag getParent() {
return jspTag;
}
public void setParent(JspTag jspTag) {
this.jspTag = jspTag;
}
public void setJspBody(JspFragment jf) {
this.setJf(jf);
}
public void setJspContext(JspContext jspContext) {
this.jspContext = jspContext;
}
public JspTag getJspTag() {
return jspTag;
}
public void setJspTag(JspTag jspTag) {
this.jspTag = jspTag;
}
public JspContext getJspContext() {
return jspContext;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getPageIdx() {
return pageIdx;
}
public void setPageIdx(int pageIdx) {
this.pageIdx = pageIdx;
}
public void setJf(JspFragment jf) {
this.jf = jf;
}
public JspFragment getJf() {
return jf;
}
}
其他:有可能
1:通过name查找,有重复
2:添加的点击事件的写法,当前浏览器不支持
上一个:请问如何写jsp代码从上一个跳转过来的网页的url判断本网页里的某些div不显示呢?
下一个:jsp上传图片并产生缩略图的代码