


Detailed explanation of front-end code implementation and request processing of JavaScript paging function
This article mainly introduces the js paging front-end code implementation and request processing in detail. It has certain reference value. Interested friends can refer to
js front-end implementation and request of paging. The processing code is for your reference. The specific content is as follows
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="css/public.css" charset='utf-8'> </head> <body> <p class='box'> <h2> <span>编号</span> <span>姓名</span> <span>性别</span> <span>分数</span> </h2> <ul class='con' id='content'> <li> <span>1</span> <span>xxx</span> <span>男</span> <span>90</span> </li> </ul> <p class='page' id='page'> <span>FIRST</span> <span>PREV</span> <ul class='pageNum' id='pageNum'> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> <span>NEXT</span> <span>LAST</span> <input type="text" id='numInp' value='1'/> </p> </p> <script src='js/ajax.js'></script> <script> var pageModule = (function(){ //获取需要操作的DOM元素 var content = document.getElementById('content'), page = document.getElementById('page'), pageNum = document.getElementById('pageNum'), numInp = document.getElementById('numInp'); //设定当前也和总页数及本次请求的数据 var n = 1,total = 0,data = null; //实现页面数据绑定及其他数据的绑定 function bindHTML(){ //content bind var str = ''; for(var i = 0;i<data.length;i++){ var curData = data[i]; str+='<li studentId="'+curData["id"]+'">'; str+='<span>'+curData["id"]+'</span>'; str+='<span>'+curData["name"]+'</span>'; str+='<span>'+(curData["sex"]==1 ? "女" : "男")+'</span>'; str+='<span>'+curData["score"]+'</span>'; str+='</li>'; } content.innerHTML = str; //page bind str = ''; for(i = 1;i<=total;i++){ if(i===n){ str+='<li class="bg">'+i+'</li>'; continue; } str+='<li>'+i+'</li>'; } pageNum.innerHTML = str; //numInp bind numInp.value = n; } //事件委托实现分页区域的按钮操作 给文本框enter键绑定操作 function bindEvent(){ page.onclick = function(e){ e = e || window.event; var tar = e.target || e.srcElement tarTag = tar.tagName.toUpperCase(), tarInn = tar.innerHTML; if(tarTag==="SPAN"){ if(tarInn==="FIRST"){ if(n===1){ return; } n = 1; } if(tarInn==="LAST"){ if(n === total){ return; } n = total; } if(tarInn==="PREV"){ if(n === 1){ return; } n--; } if(tarInn==="NEXT"){ if(n === total){ return; } n++; } } if(tarTag==="LI"){ if(n === parseFloat(tarInn)){ return; } n = parseFloat(tarInn); } //input if(tarTag==="INPUT"){ return; } //重新发送请求 sendAJAX() } numInp.onkeyup = function(e){ e = e || window.event; if(e.keyCode===13){//enter键 var val = parseFloat(this.value.replace(/^ +| +$/,'')); if(isNaN(val)){ this.value = n; return; } val = Math.round(val) if(val<1){ n = 1; }else if(val>total){ n = total; }else{ n = val; } sendAJAX(); } } } //content区域的LI跳转事件 function bindLink(){ var oLis = content.getElementsByTagName('li'); for(var i = 0;i<oLis.length;i++){ oLis[i].onclick = function(){ // window.location.href = "detail.html"; //在跳转的时候还需要把当前点击学员得ID传到详情页面 window.open("detail.html?id="+this.getAttribute('studentId')); } } } function sendAJAX(){ ajax({ url:"/getList?n="+n, success:function(jsonData){ if(jsonData && jsonData.code===0){ total = jsonData["total"]; data = jsonData['data']; bindHTML(); bindLink(); } } }) } //模块入口 function init(){ sendAJAX(); bindEvent(); } return { init:init } })() pageModule.init(); </script> </body> </html>
detail.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="css/public.css" charset='utf-8'> </head> <body> <ul class='box2' id='box2'> <li> <span>编号</span> <span>4</span> </li> <li> <span>姓名</span> <span>xxx</span> </li> <li> <span>性别</span> <span>男</span> </li> <li> <span>分数</span> <span>99</span> </li> </ul> <script src='js/ajax.js'></script> <script> String.prototype.queryURLParameter = function(){ //PARAMETER var obj = {}, reg = /([^?=]+)=([^?=]+)/g; this.replace(reg,function(){ var key = arguments[1], value = arguments[2]; obj[key] = value; }); //->HASH // reg = /#([^?=]+)/; // if (reg.test(this)) { // obj['hash'] = reg.exec(this)[1]; // } return obj; } var detailModuel = (function(){ var data = null,urlId = window.location.href.queryURLParameter().id,oBox = document.getElementById('box2'); function bindHTML(){ var str = ""; str+="<li><span>编号</span><span>"+data["id"]+"</span></li>"; str+="<li><span>编号</span><span>"+data["name"]+"</span></li>"; str+="<li><span>编号</span><span>"+(data["sex"]==1 ? "男" : "女")+"</span></li>"; str+="<li><span>编号</span><span>"+data["score"]+"</span></li>"; oBox.innerHTML = str; } function init(){ ajax({ url:"/getInfo?id="+urlId, success:function(jsonData){ if(jsonData && jsonData.code===0){ data = jsonData["data"]; bindHTML(); } } }) } return { init:init } })() detailModuel.init(); </script> </body> </html>
Final rendering:
The above is the detailed content of Detailed explanation of front-end code implementation and request processing of JavaScript paging function. For more information, please follow other related articles on the PHP Chinese website!

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft