首先,我把出错的原因给大家说一下,下面是 测试页面的部分代码,
当我在加入 <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>
当我在加入 <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>