问题描述
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><SCRIPT LANGUAGE="JavaScript"><!--function insertStr(){var strs = document.getElementById("strid").value;var str =ttt.value;strs = strs+str+";"alert(strs); document.getElementById("strid").value = strs;instStr(1);}//--></SCRIPT> <body onload="instStr(1)"> <INPUT TYPE="hidden" NAME="" id="strid" value="你好1;你好2;你好3;你好4;你好5;你好6;你好7;你好8;你好9;你好10;你好11;你好12;你好13;你好14;你好15;你好16;你好17;你好18;你好19;你好20;你好21;你好22;你好23;你好24;你好25;你好26;你好27;你好28;你好29;你好30;你好31;你好32;你好33;你好34;你好35;你好36;你好37;你好38;你好39;你好40;你好41;"></TEXTAREA> <TABLE id="recordTable" border="1"> </TABLE> <span id="span1"></span><br/> <INPUT TYPE="text" NAME="ttt" id="ttt"> <INPUT TYPE="button" VALUE="添加" ONCLICK="insertStr()"> </body> <script type="text/javascript">function instStr(spanid){var str = document.getElementById("strid").value;//alert(str);//字的总集合var strArray = str.split(";");//页数var page =spanid;end = (page-1)*4+4;var sumPage = Math.round((strArray.length-1)/4 );if(Math.round((strArray.length-1)/4 )>0)sumPage = sumPage+1;var strrs="";for(k = 1; k <= sumPage; k++){if(k==1)strrs +="<span id='"+k+"' onclick='instStr("+k+")'>首页</span>";else{if(k==sumPage){strrs +="<span id='"+k+"' onclick='instStr("+k+")'>末页</span>";}elsestrrs +="<span id='"+k+"' onclick='instStr("+k+")'>"+k+"</span>";}}document.getElementById("span1").innerHTML=(strrs);if(page==sumPage){ strrs = " <TABLE id='recordTable' border='1'> </TABLE> ";for(i = (page-1)*4;i < strArray.length-1;i++){if(Math.round(i/2)>0) var row = recordTable.insertRow(recordTable.rows.length); var col = row.insertCell(0); col.innerHTML = "<span id='"+i+"' name='"+strArray+"'value='"+strArray[i]+"' onclick='strPage()'>"+strArray[i]+"</span>"; } alert(page);}else{for(i = (page-1)*4;i < end;i++){if(i%2==0) var row = recordTable.insertRow(recordTable.rows.length); var col = row.insertCell(0); col.innerHTML = "<span id='"+i+"' name='"+strArray[i]+"'value='"+strArray[i]+"' onclick='strPage()'>"+strArray[i]+"</span>"; }}}function strPage(){var str= document.getElementById(1).value;alert(str);}</script></html>[i]谢谢高手请指点一下为什么每次点击下一页的时候总是在下面加而不是直接显示那一页的内容呢。请帮忙解决一下。问题补充:问题解决了删除了前面的行了,可是到了最后一页的时候就变样了,这是为什么呢问题补充:是我没有复制好!!谢谢了!!解决了!!!!:)
解决方案
贴个js的好像没问题^_^
解决方案二:
好像code的html格式有点问题,我贴的removeAllRows()里面的参数名怎么double了,bug???function removeAllRows(){ var rowNum=recordTable.rows.length; for (i=0;i<rowNum;i++) { recordTable.deleteRow(i); rowNum=rowNum-1; i=i-1; } }
解决方案三:
因为换页instStr()函数每次都是insertRow,而没有把以前的row清掉,所以一直都是递增了<%@ page language="java" import="java.util.*" pageEncoding="GBK"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><SCRIPT LANGUAGE="JavaScript"><!--function insertStr(){var strs = document.getElementById("strid").value;var str =ttt.value;strs = strs+str+";"alert(strs);document.getElementById("strid").value = strs;instStr(1);}//--></SCRIPT><body onload="instStr(1)"><INPUT TYPE="hidden" NAME="" id="strid" value="你好1;你好2;你好3;你好4;你好5;你好6;你好7;你好8;你好9;你好10;你好11;你好12;你好13;你好14;你好 15;你好16;你好17;你好18;你好19;你好20;你好21;你好22;你好23;你好24;你好25;你好26;你好27;你好28;你好 29;你好30;你好31;你好32;你好33;你好34;你好35;你好36;你好37;你好38;你好39;你好40;你好41;"><TABLE id="recordTable" border="1"></TABLE><span id="span1"></span><br/><INPUT TYPE="text" NAME="ttt" id="ttt"><INPUT TYPE="button" VALUE="添加" ONCLICK="insertStr()"></body><script type="text/javascript">function instStr(spanid){var str = document.getElementById("strid").value;// alert(str);//字的总集合var strArray = str.split(";");//页数var page =spanid;end = (page-1)*4+4;var sumPage = Math.round((strArray.length-1)/4 );if(Math.round((strArray.length-1)/4 )>0)sumPage = sumPage+1;var strrs="";for(k = 1; k <= sumPage; k++){if(k==1)strrs +="<span id='"+k+"' onclick='instStr("+k+")'>首页</span>";else{if(k==sumPage){strrs +="<span id='"+k+"' onclick='instStr("+k+")'>末页</span>";}elsestrrs +="<span id='"+k+"' onclick='instStr("+k+")'>"+k+"</span>";}}document.getElementById("span1").innerHTML=(strrs);if(page==sumPage){strrs = " <TABLE id='recordTable' border='1'> </TABLE> ";removeAllRows();for(i = (page-1)*4;i < strArray.length-1;i++){if(Math.round(i/2)>0)var row = recordTable.insertRow(recordTable.rows.length);var col = row.insertCell(0);col.innerHTML = "<span id='"+i+"' name='"+strArray+"'value='"+strArray[i]+"' onclick='strPage()'>"+strArray[i]+"</span>";}alert(page);}else{removeAllRows();for(i = (page-1)*4;i < end;i++){if(i%2==0)var row = recordTable.insertRow(recordTable.rows.length);var col = row.insertCell(0);col.innerHTML = "<span id='"+i+"' name='"+strArray[i]+"'value='"+strArray[i]+"' onclick='strPage()'>"+strArray[i]+"</span>";}}}function strPage(){var str= document.getElementById(1).value;alert(str);}function removeAllRows(){ var rowNum=recordTable.rows.length; for (i=0;i<rowNum;i++) { recordTable.deleteRow(i); rowNum=rowNum-1; i=i-1; } }</script></html>