列表

详情


JS15. 生成页码

描述

请补全JavaScript代码,要求根据参数动态生成"li"标签页码并插入"ul"标签下。要求如下:
1. "allItem"为总数据项个数,"pageItem"为每页的数据项个数
2. "li"标签内容为当前页码数,页码从1开始

示例1

输入:

_createPage(13,2)

输出:

"li"长度为7,"li"内容依次为"1","2","3","4","5","6","7"

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 1737ms, 内存消耗: 77800KB, 提交时间: 2021-12-05

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<ul id=\"ul\">\n            \n        </ul>\n        <script type=\"text/javascript\">\n           const _createPage = (allItem, pageItem) => {\n                // 补全代码\n                let num=Math.ceil(allItem/pageItem);\n                for (let index = 0; index < num; index++) {\n                 let li=document.createElement('li')\n                 li.innerHTML=String(index+1);\n                 ul.appendChild(li)\n                  \n                }\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1739ms, 内存消耗: 77772KB, 提交时间: 2021-12-05

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<ul id=\"ul\">\n            \n        </ul>\n        <script type=\"text/javascript\">\n            const _createPage = (allItem, pageItem) => {\n                // 补全代码\n                let num = Math.ceil(allItem / pageItem);\n                let oUl = document.getElementById(\"ul\");\n                for(let i=1;i<=num;i++)\n                    {\n                        let oLi = document.createElement(\"li\");\n                        oLi.innerHTML = i;\n                        oUl.appendChild(oLi);\n                    }\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1739ms, 内存消耗: 77800KB, 提交时间: 2021-12-05

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<ul id=\"ul\">\n            \n        </ul>\n        <script type=\"text/javascript\">\n    \n    const _createPage = (allItem, pageItem) => {\n      // 补全代码\n        let ul = document.querySelector('#ul')\n      let num = Math.ceil(allItem / pageItem)\n      for (let i = 1; i <= num; i++) {\n        let li = document.createElement('li');\n        li.innerHTML = i;\n        ul.appendChild(li);\n      }\n    }\n  </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1740ms, 内存消耗: 77808KB, 提交时间: 2021-12-31

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<ul id=\"ul\">\n            \n        </ul>\n        <script type=\"text/javascript\">\n            const _createPage = (allItem, pageItem) => {\n                // 补全代码\n                const ul = document.querySelector('#ul')\n                const len = Math.ceil(allItem / pageItem)\n                for(let i=0; i<len; i++) {\n                    let li = document.createElement('li')\n                    li.innerText = `${i+1}`\n                    ul.appendChild(li)\n                }\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1740ms, 内存消耗: 77864KB, 提交时间: 2022-02-02

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <style>\n        li{\n            list-style:none;\n        }\n    </style>\n    <body>\n    \t<ul id=\"ul\">\n            \n        </ul>\n        <script type=\"text/javascript\">\n            const _createPage = (allItem, pageItem) => {\n                // 补全代码\n                let ul = document.querySelector('#ul')\n                let num = Math.ceil(allItem / pageItem)\n                for(let i = 1;i <= num ;i++){\n                    let li = document.createElement('li')\n                    li.innerHTML = i\n                    ul.append(li)\n                }\n            }\n        </script>\n    </body>\n</html>","libs":[]}

上一题