自己写了个分页的JS 类函数,把它封装好后,测试的过程中,却出现个奇怪的问题!!...

首先,我把出错的原因给大家说一下,下面是 测试页面的部分代码,
当我在加入 <form></form> 标签之后, 当点击'GO' 按钮的时候,
就出现了莫名其妙的错误: '对象不支持此属性或方法',
当把 <form></form> 删除以后,就正常了。
这个问题困扰我许久了,希望大家把帮我看一下,到底是哪个地方的代码出现了错误。。。

[color=red]<!-- <form> -->[/color]
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="0" class="frame" >
<thead>
<tr>
<td align='center' colspan="" id='page'>
<script>
var url = "/Lottery.do?op=forwardAddPaiLie3";
var page1 = new pageObject(url,1,45,450,"page1");

</script>
</td>
</tr>
</thead>
</table>
[color=red]<!-- </form> -->[/color]


下面是 JS 函数。
// 校验数字
<script>
function checkNumber(obj)
{
var reg = /[1-9]{1}([0-9]*)$/;
return reg.test(obj);
}

function pageObject(url,currentPage,totalPage,recordSize)
{
// 对象名称
_OBJ_NAME = this;
// 查询的URL 和QueryString
this.url = url;
// 当前页
this.currentPage = currentPage;
// 共多少页
this.totalPage = totalPage;
// 共多少条记录
this.recordSize = recordSize;
// document.write 的字符串
this.toWrite = "";

// 初始化函数
this.init = function()
{
if(this.totalPage == 1 && this.currentPage == 1)
{
this.toWrite="(第<font color=blue>"+this.currentPage+"</font>/"+this.totalPage+"页 共"+this.recordSize+"条)";
this.toWrite += " 首页 上一页 下一页 末页 <input id='forwardPage' size='4' value='' style='ime-mode:disabled;'> <input type='button' value=' GO ' class='button' οnclick='"+"_OBJ_NAME.fnForward()'>";
}else if(this.totalPage > 1 && this.currentPage==1)
{
var next = parseInt(this.currentPage)+1;
this.toWrite="(第<font color=blue>"+this.currentPage+"</font>/"+this.totalPage+"页 共"+this.recordSize+"条)";
this.toWrite += " 首页 上一页 <a href='"+this.url+"&_pageNo="+next+"'>下一页</a>";
this.toWrite += " <a href='"+this.url+"&_pageNo="+this.totalPage+"'>末页</a>  <input id='forwardPage' size='4' value='' style='ime-mode:disabled;'> <input type='button' value=' GO ' class='button' οnclick='"+"_OBJ_NAME.fnForward()'>";
}else if(this.totalPage >1 && this.currentPage != this.totalPage)
{
var next = parseInt(this.currentPage)+1;
var previous = parseInt(this.currentPage)-1;
this.toWrite="(第<font color=blue>"+this.currentPage+"</font>/"+this.totalPage+"页 共"+this.recordSize+"条)";
this.toWrite += " <a href='"+this.url+"&_pageNo=1'>首页</a> <a href='"+this.url+"&_pageNo="+previous+"'>上一页</a> ";
this.toWrite += "<a href='"+this.url+"&_pageNo="+next+"'>下一页</a> <a href='"+this.url+"&_pageNo="+this.totalPage+"'>末页</a>";
this.toWrite += " <input id='forwardPage' size='4' value='' style='ime-mode:disabled;'> <input type='button' value=' GO ' class='button' οnclick='"+"_OBJ_NAME.fnForward()'>";
}else if(this.totalPage>1 && this.currentPage==this.totalPage)
{
var previous = parseInt(this.currentPage)-1;
this.toWrite="(第<font color=blue>"+this.currentPage+"</font>/"+this.totalPage+"页 共"+this.recordSize+"条)";
this.toWrite += " <a href='"+this.url+"&_pageNo=1'>首页</a> <a href='"+this.url+"&_pageNo="+previous+"'>上一页</a> ";
this.toWrite += "下一页 末页";
this.toWrite += " <input id='forwardPage' size='4' value='' style='ime-mode:disabled;'> <input type='button' value=' GO ' class='button' οnclick='"+"_OBJ_NAME.fnForward()'>";
}
document.getElementById('page').innerHTML = this.toWrite;
};

this.init();
// 跳转函数。
this.fnForward = function()
{
var val = document.getElementById('forwardPage').value;
if(!checkNumber(val))
{
alert('请输入数字!');
document.getElementById('forwardPage').select();
return;
}

if(parseInt(val) > this.totalPage)
{
alert('不能超过最大的页数!');
document.getElementById('forwardPage').value = this.totalPage;
return;
}

location.href = this.url +"&_pageNo="+parseInt(val);
};
}

</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值