吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1263|回复: 17
收起左侧

[求助] JavaScript问题,为什么实现不了想要的功能呢

[复制链接]
拨Q 发表于 2021-11-15 00:47
40吾爱币
这是一个长文章自动分页的js,但是好像出了点问题,没法点击,求大佬看看
[HTML] 纯文本查看 复制代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style>
* {
font-size:10.2pt;
font-family:tahoma;
line-height:150%;
}
.divContent
{
border:1px solid red;
background-color:#FFD2D3;
width:500px;
word-break:break-all;
margin:10px 0px 10px;
padding:10px;
}
</style>
</HEAD>
<BODY>
header
<div id="divPagenation"></div>
<div id="divContent"></div>
footer
<SCRIPT LANGUAGE="JavaScript">
<!--
s="<p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:“牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。” </p><p>“班上一个调皮鬼对此并不满意。他说:“兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。” </p><p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:“牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。” </p><p>“班上一个调皮鬼对此并不满意。他说:“兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。” </p><p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:“牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。” </p><p>“班上一个调皮鬼对此并不满意。他说:“兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。” </p><p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:“牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。” </p><p>“班上一个调皮鬼对此并不满意。他说:“兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。” </p><p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:“牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。” </p><p>“班上一个调皮鬼对此并不满意。他说:“兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。” </p>";
function DHTMLpagenation(content) { with (this)
{
 // client static html file pagenation
 // Scipit by blueDestiny

 this.content=content;
 this.contentLength=content.length;
 this.pageSizeCount;
 this.perpageLength=100; //default perpage byte length.
 this.currentPage=1;
 //this.regularExp=/.+[\?\&]{1}page=(\d+)/;
 this.regularExp=/\d+/;

 this.divDisplayContent;
 this.contentStyle=null;
 this.strDisplayContent="";
 this.divDisplayPagenation;
 this.strDisplayPagenation="";
 
 arguments.length==2?perpageLength=arguments[1]:'';

 try {
  divExecuteTime=document.createElement("DIV");
  document.body.appendChild(divExecuteTime);
 }
 catch(e)
 {
 }

 if(document.getElementById("divPagenation"))
 {
  divDisplayPagenation=document.getElementById("divPagenation");
 }
 else
 {
  try
  {
   divDisplayPagenation=document.createElement("DIV");
   divDisplayPagenation.id="divPagenation";
   document.body.appendChild(divDisplayPagenation);
  }
  catch(e)
  {
   return false;
  }
 }
 if(document.getElementById("divContent"))
 {
  divDisplayContent=document.getElementById("divContent");
 }
 else
 {
  try
  {
   divDisplayContent=document.createElement("DIV");
   divDisplayContent.id="divContent";
   document.body.appendChild(divDisplayContent);
  }
  catch(e)
  {
   return false;
  }
 }

 DHTMLpagenation.initialize();
 return this;
 
}};
DHTMLpagenation.initialize=function() { with (this)
{
 divDisplayContent.className=contentStyle!=null?contentStyle:"divContent";
 if(contentLength<=perpageLength)
 {
  strDisplayContent=content;
  divDisplayContent.innerHTML=strDisplayContent;
  return null;
 }

 pageSizeCount=Math.ceil((contentLength/perpageLength));

 DHTMLpagenation.goto(currentPage);
 DHTMLpagenation.displayContent();
}};
DHTMLpagenation.displayPage=function() { with (this)
{
 strDisplayPagenation="分页:";

 if(currentPage&¤tPage!=1)
  strDisplayPagenation+='<a href="javascript:void(0)" οnclick="DHTMLpagenation.previous()">上一页</a>  ';
 else
  strDisplayPagenation+="上一页  ";

 for(var i=1;i<=pageSizeCount;i++)
 {
  if(i!=currentPage)
   strDisplayPagenation+='<a href="javascript:void(0)" οnclick="DHTMLpagenation.goto('+i+');">'+i+'</a>  ';
  else
   strDisplayPagenation+=i+"  ";
 }

 if(currentPage&¤tPage!=pageSizeCount)
  strDisplayPagenation+='<a href="javascript:void(0)" οnclick="DHTMLpagenation.next()">下一页</a>  ';
 else
  strDisplayPagenation+="下一页  ";

 strDisplayPagenation+="共 " + pageSizeCount + " 页,每页" + perpageLength + " 字符,调整字符数:<input type='text' value='"+perpageLength+"' id='ctlPerpageLength'><input type='button' value='确定' οnclick='DHTMLpagenation.change(document.getElementById(\"ctlPerpageLength\").value);'>";

 divDisplayPagenation.innerHTML=strDisplayPagenation;
}};
DHTMLpagenation.previous=function() { with(this)
{
 DHTMLpagenation.goto(currentPage-1);
}};
DHTMLpagenation.next=function() { with(this)
{
 DHTMLpagenation.goto(currentPage+1);
}};
DHTMLpagenation.goto=function(iCurrentPage) { with (this)
{
 startime=new Date();
 if(regularExp.test(iCurrentPage))
 {
  currentPage=iCurrentPage;
  strDisplayContent=content.substr((currentPage-1)*perpageLength,perpageLength);
 }
 else
 {
  alert("page parameter error!");
 }
 DHTMLpagenation.displayPage();
 DHTMLpagenation.displayContent();
}};
DHTMLpagenation.displayContent=function() { with (this)
{
 divDisplayContent.innerHTML=strDisplayContent;
}};
DHTMLpagenation.change=function(iPerpageLength) { with(this)
{
 if(regularExp.test(iPerpageLength))
 {
  DHTMLpagenation.perpageLength=iPerpageLength;
  DHTMLpagenation.currentPage=1;
  DHTMLpagenation.initialize();
 }
 else
 {
  alert("请输入数字");
 }
}};

// method
// DHTMLpagenation(strContent,perpageLength)

DHTMLpagenation(s,100);

//-->
</SCRIPT>
</BODY>
</HTML>

最佳答案

查看完整内容

New Document * { font-size: 10.2pt; font-family: tahoma; line-height: 150%; } .divContent { border: 1px solid red; background-color: #FFD2D3; width: 500px; word-break: break-all; margin: 10px 0px 10px; padding: 10px; } header footer s = "女老师竭 ...

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
为之奈何? + 1 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

shabaobao 发表于 2021-11-15 00:47
拨Q 发表于 2021-11-15 20:25
大哥,这个页码的点击怎么改啊,

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>

<HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <style>
    * {
      font-size: 10.2pt;
      font-family: tahoma;
      line-height: 150%;
    }

    .divContent {
      border: 1px solid red;
      background-color: #FFD2D3;
      width: 500px;
      word-break: break-all;
      margin: 10px 0px 10px;
      padding: 10px;
    }
  </style>
</HEAD>

<BODY>
  header
  <div id="divPagenation"></div>
  <div id="divContent"></div>
  footer
  <SCRIPT LANGUAGE="JavaScript">

    s = "<p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:“牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。” </p><p>“班上一个调皮鬼对此并不满意。他说:“兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。” </p><p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:“牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。” </p><p>“班上一个调皮鬼对此并不满意。他说:“兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。” </p><p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:“牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。” </p><p>“班上一个调皮鬼对此并不满意。他说:“兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。” </p><p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:“牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。” </p><p>“班上一个调皮鬼对此并不满意。他说:“兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。” </p><p>女老师竭力向孩子们证明,学习好功课的重要性。 </p><p>她说:“牛顿坐在树下,眼睛盯着树在思考,这时,有一个苹果落在他的头上,于是他发现了万有引力定律,孩子们,你们想想看,做一位伟大的科学家多么好,多么神气啊,要想做到这一点,就必须好好学习。” </p><p>“班上一个调皮鬼对此并不满意。他说:“兴许是这样,可是,假如他坐在学校里,埋头书本,那他就什么也发现不了啦。” </p>";

    function DHTMLpagenation(c /*content*/, p /**perpageLength*/) {

      // client static html file pagenation
      // Scipit by blueDestiny

      content = c;
      contentLength = content.length;
      // pageSizeCount;
      perpageLength = p; //default perpage byte length.
      currentPage = 1;
      //this.regularExp=/.+[\?\&]{1}page=(\d+)/;
      regularExp = /\d+/;

      contentStyle = null;
      strDisplayContent = "";
      strDisplayPagenation = "";

      arguments.length == 2 ? perpageLength = arguments[1] : '';

      divExecuteTime = document.createElement("DIV");
      document.body.appendChild(divExecuteTime);


      if (document.getElementById("divPagenation")) {
        divDisplayPagenation = document.getElementById("divPagenation");
      }
      else {

        divDisplayPagenation = document.createElement("DIV");
        divDisplayPagenation.id = "divPagenation";
        document.body.appendChild(divDisplayPagenation);
      }
      if (document.getElementById("divContent")) {
        divDisplayContent = document.getElementById("divContent");
      }
      else {

        divDisplayContent = document.createElement("DIV");
        divDisplayContent.id = "divContent";
        document.body.appendChild(divDisplayContent);
      }
      this.initialize()
    };
    DHTMLpagenation.prototype.initialize = function () {

      divDisplayContent.className = contentStyle != null ? contentStyle : "divContent";
      if (contentLength <= perpageLength) {
        strDisplayContent = content;
        divDisplayContent.innerHTML = strDisplayContent;
        return null;
      }

      pageSizeCount = Math.ceil((contentLength / perpageLength));

      this.goto(currentPage);
      this.displayContent();
    };

    DHTMLpagenation.prototype.displayPage = function () {

      strDisplayPagenation = "分页:";

      if (currentPage > 1) {
        strDisplayPagenation += '<a href="javascript:void(0)" onclick="instance.previous()">上一页</a>  ';
      } else {
        strDisplayPagenation += "上一页  ";
      }

      for (var i = 1; i <= pageSizeCount; i++) {
        if (i != currentPage)
          strDisplayPagenation += '<a href="javascript:void(0)" onclick="instance.goto(' + i + ')">' + i + '</a>  ';
        else
          strDisplayPagenation += i + "  ";
      }

      if (currentPage < pageSizeCount) {
        strDisplayPagenation += '<a href="javascript:void(0)" onclick="instance.next()">下一页</a>  ';
      } else {
        strDisplayPagenation += "下一页  ";
      }
      strDisplayPagenation += "共 " + pageSizeCount + " 页,每页" + perpageLength + ' 字符,调整字符数:<input type="text" value="' + perpageLength + '" id="ctlPerpageLength" > <input type="button" value="确定" onclick="instance.change(document.getElementById(\'ctlPerpageLength\').value)" >';

      divDisplayPagenation.innerHTML = strDisplayPagenation;

    };

    DHTMLpagenation.prototype.previous = function () {

      this.goto(currentPage - 1);

    };
    DHTMLpagenation.prototype.next = function () {

      this.goto(currentPage + 1);

    };
    DHTMLpagenation.prototype.goto = function (iCurrentPage) {
      startime = new Date();
      if (regularExp.test(iCurrentPage)) {
        currentPage = iCurrentPage;
        strDisplayContent = content.substr((currentPage - 1) * perpageLength, perpageLength);
      }
      else {
        alert("page parameter error!");
      }
      this.displayPage();
      this.displayContent();

    };
    DHTMLpagenation.prototype.displayContent = function () {

      divDisplayContent.innerHTML = strDisplayContent;

    };
    DHTMLpagenation.prototype.change = function (iPerpageLength) {
      if (regularExp.test(iPerpageLength)) {
        perpageLength = iPerpageLength;
        currentPage = 1;
        this.initialize();
      }
      else {
        alert("请输入数字");
      }
    };

    // method
    // DHTMLpagenation(strContent,perpageLength)

    var instance = new DHTMLpagenation(s, 100);
  </SCRIPT>
</BODY>

</HTML>

免费评分

参与人数 1吾爱币 +2 热心值 +1 收起 理由
拨Q + 2 + 1 我很赞同!

查看全部评分

C哥888 发表于 2021-11-15 02:00
如果用vscode可以用插件copilot,实现AI自动编程,一直按确认就行了,代码就写好了,哪里有问题也有提示。
807G 发表于 2021-11-15 08:16
jerryowner 发表于 2021-11-15 08:23
学习一下
我今天是大佬 发表于 2021-11-15 08:51
能有大概效果图不, 不然无法想想啊
张海洋 发表于 2021-11-15 09:34
在浏览器里打断点看看
qingugu 发表于 2021-11-15 09:41
用的什么软件?
leftnight 发表于 2021-11-15 09:46
你这个代码一运行就报错呀, ¤tPage这个变量删除了,才显示正常。
WX20211115-094411.png
Aaron-x 发表于 2021-11-15 10:02
用插件就行了吗
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-13 22:33

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表