- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家好,我使用测验模块,
所以问题是,我从数组动态生成了数据,这是我呈现给 View 的数据,效果很好。
我有左侧选项卡,这些选项卡是根据问题的长度构建的。
所以我需要在页面中显示前 10 个带有问题的选项卡,这些都已完成。
当我按下按钮下一个问题时,它将转到下一个问题,但如果问题超过 10 个,则不会将 View 更改为下一个 10,以防万一如果我手动更改 View ,使用按钮“">”,它会显示新 View ,但是当我按下按钮下一个问题时,它会从头开始 =(
使用此函数,我对页面中的 li
元素进行排序:
function sortTabs() {
var $lis = $("#left-tabs li").hide();
$lis.slice(0, 10).show();
var size_li = $lis.length;
var x = 10,
start = 0;
console.log(start, x , size_li)
$('.nex-ten').click(function () {
if (start + x < size_li) {
$lis.slice(start, start + x).hide();
start += x;
$lis.slice(start, start + x).show();
}
});
$('.prev-ten').click(function () {
if (start - x >= 0) {
$lis.slice(start, start + x).hide();
start -= x;
$lis.slice(start, start + x).show();
}
});
}
最佳答案
而不是构建这样一个复杂的 View 然后使用它。你可以玩数据。因为您一次只显示 10 个数据。您一次只能构建 10 行。它也会优化你的用户界面。否则系统就会死掉。以下是一些示例方法。您可以相应地优化它。
查找更新代码笔:
https://codepen.io/deepakshrma/pen/jOPWbKW
斯普莱:
const onNext = () => {
pageInfo.curr = pageInfo.curr + 1;
if (pageInfo.curr >= pageInfo.limit) {
pageInfo.page = pageInfo.page + 1;
pageInfo.curr = pageInfo.curr - 10;
if (pageInfo.page > PAGE_COUNT) {
pageInfo.page = 0;
pageInfo.curr = 0;
}
}
console.log(pageInfo);
};
//app.js
var allQuestions = [
{
question:
'Who said, "My real father lost his head at Kings Landing. I made a choice, and I chose wrong."',
choices: [
"Robb Stark",
"Jon Snow",
"Theon Greyjoy",
"Arya Stark",
"Arya Stark",
"Arya Stark",
"Arya Stark"
],
answer: "Jon Snow",
image: "https://www.w3schools.com/howto/img_mountains.jpg"
},
{
question: "What does Valar Morghulis mean?",
choices: [
"All men must die",
"What is dead may never die",
"Never say never",
"All men must first live",
"Robb Stark",
"Jon Snow",
"Theon Greyjoy"
],
answer: "All men must die",
image:
"https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
},
{
question:
"Which GOT character played Hermoine Granger's mom in Harry Potter?",
choices: ["Melisandre", "Alerie Tyrell"],
answer: "Melisandre",
image:
"https://media.gettyimages.com/photos/beautiful-book-picture-id865109088?s=612x612"
},
{
question:
'Who said, "You knelt as boys, now rise as men of the Nights Watch."?',
choices: [
"Maester Aemon",
"Eddard Stark",
"Jeor Mormont",
"Alliser Thorne"
],
answer: "Maester Aemon",
image: "https://tinypng.com/images/social/website.jpg"
},
{
question: "What is Daenerys Targaryens brothers name?",
choices: ["Varys", "Viserys", "Aerys", "Aegon"],
answer: 1,
image: ""
},
{
question: "What is a big fear of the Dothraki?",
choices: ["Fire", "Salt water", "Heavy stone", "Crows"],
answer: 1,
image: ""
},
{
question: "How many swords make up the Iron Throne?",
choices: ["500", "1000", "2000", "5000"],
answer: 1,
image: ""
},
{
question: "What were Jon Arryn's final words?",
choices: [
"Winter is coming",
"Beware of the white walkers",
"The seed is strong",
"Beware the dwarf"
],
answer: 2,
image: ""
},
{
question: "Who built the Iron Throne?",
choices: [
"Aerys the Mad King",
"Aegon The Unlikely",
"Aegon the Conqueror",
"Aegon the Destroyer"
],
answer: 2,
image: ""
},
{
question: "Which knight takes a lance through the neck while jousting?",
choices: [
"Ser Hugh of the Vale",
"Ser Barristan Selmy",
"Ser Ilyn Payne",
"Ser Gregor Clegane"
],
answer: 0,
image: ""
},
{
question: "What does Valar Morghulis mean?",
choices: [
"All men must die",
"What is dead may never die",
"Never say never",
"All men must first live",
"Robb Stark",
"Jon Snow",
"Theon Greyjoy"
],
answer: "All men must die",
image:
"https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
},
{
question:
"Which GOT character played Hermoine Granger's mom in Harry Potter?",
choices: ["Melisandre", "Alerie Tyrell"],
answer: "Melisandre",
image:
"https://media.gettyimages.com/photos/beautiful-book-picture-id865109088?s=612x612"
},
{
question:
'Who said, "You knelt as boys, now rise as men of the Nights Watch."?',
choices: [
"Maester Aemon",
"Eddard Stark",
"Jeor Mormont",
"Alliser Thorne"
],
answer: "Maester Aemon",
image: "https://tinypng.com/images/social/website.jpg"
},
{
question: "What does Valar Morghulis mean?",
choices: [
"All men must die",
"What is dead may never die",
"Never say never",
"All men must first live",
"Robb Stark",
"Jon Snow",
"Theon Greyjoy"
],
answer: "All men must die",
image:
"https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
},
{
question:
"Which GOT character played Hermoine Granger's mom in Harry Potter?",
choices: ["Melisandre", "Alerie Tyrell"],
answer: "Melisandre",
image:
"https://media.gettyimages.com/photos/beautiful-book-picture-id865109088?s=612x612"
},
{
question:
'Who said, "You knelt as boys, now rise as men of the Nights Watch."?',
choices: [
"Maester Aemon",
"Eddard Stark",
"Jeor Mormont",
"Alliser Thorne"
],
answer: "Maester Aemon",
image: "https://tinypng.com/images/social/website.jpg"
},
{
question: "Who built the Iron Throne?",
choices: [
"Aerys the Mad King",
"Aegon The Unlikely",
"Aegon the Conqueror",
"Aegon the Destroyer"
],
answer: 2,
image: ""
},
{
question: "Which knight takes a lance through the neck while jousting?",
choices: [
"Ser Hugh of the Vale",
"Ser Barristan Selmy",
"Ser Ilyn Payne",
"Ser Gregor Clegane"
],
answer: 0,
image: ""
},
{
question: "What does Valar Morghulis mean?",
choices: [
"All men must die",
"What is dead may never die",
"Never say never",
"All men must first live",
"Robb Stark",
"Jon Snow",
"Theon Greyjoy"
],
answer: "All men must die",
image:
"https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
},
{
question:
"Which GOT character played Hermoine Granger's mom in Harry Potter?",
choices: ["Melisandre", "Alerie Tyrell"],
answer: "Melisandre",
image:
"https://media.gettyimages.com/photos/beautiful-book-picture-id865109088?s=612x612"
},
{
question:
'Who said, "You knelt as boys, now rise as men of the Nights Watch."?',
choices: [
"Maester Aemon",
"Eddard Stark",
"Jeor Mormont",
"Alliser Thorne"
],
answer: "Maester Aemon",
image: "https://tinypng.com/images/social/website.jpg"
},
{
question: "What does Valar Morghulis mean?",
choices: [
"All men must die",
"What is dead may never die",
"Never say never",
"All men must first live",
"Robb Stark",
"Jon Snow",
"Theon Greyjoy"
],
answer: "All men must die",
image:
"https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
},
{
question:
"Which GOT character played Hermoine Granger's mom in Harry Potter?",
choices: ["Melisandre", "Alerie Tyrell"],
answer: "Melisandre",
image:
"https://media.gettyimages.com/photos/beautiful-book-picture-id865109088?s=612x612"
},
{
question:
'Who said, "You knelt as boys, now rise as men of the Nights Watch."?',
choices: [
"Maester Aemon",
"Eddard Stark",
"Jeor Mormont",
"Alliser Thorne"
],
answer: "Maester Aemon",
image: "https://tinypng.com/images/social/website.jpg"
},
{
question: "Who built the Iron Throne?",
choices: [
"Aerys the Mad King",
"Aegon The Unlikely",
"Aegon the Conqueror",
"Aegon the Destroyer"
],
answer: 2,
image: ""
},
{
question: "Which knight takes a lance through the neck while jousting?",
choices: [
"Ser Hugh of the Vale",
"Ser Barristan Selmy",
"Ser Ilyn Payne",
"Ser Gregor Clegane"
],
answer: 0,
image: ""
},
{
question: "What does Valar Morghulis mean?",
choices: [
"All men must die",
"What is dead may never die",
"Never say never",
"All men must first live",
"Robb Stark",
"Jon Snow",
"Theon Greyjoy"
],
answer: "All men must die",
image:
"https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
},
{
question:
"Which GOT character played Hermoine Granger's mom in Harry Potter?",
choices: ["Melisandre", "Alerie Tyrell"],
answer: "Melisandre",
image:
"https://media.gettyimages.com/photos/beautiful-book-picture-id865109088?s=612x612"
},
{
question:
'Who said, "You knelt as boys, now rise as men of the Nights Watch."?',
choices: [
"Maester Aemon",
"Eddard Stark",
"Jeor Mormont",
"Alliser Thorne"
],
answer: "Maester Aemon",
image: "https://tinypng.com/images/social/website.jpg"
},
{
question: "What does Valar Morghulis mean?",
choices: [
"All men must die",
"What is dead may never die",
"Never say never",
"All men must first live",
"Robb Stark",
"Jon Snow",
"Theon Greyjoy"
],
answer: "All men must die",
image:
"https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
},
{
question:
"Which GOT character played Hermoine Granger's mom in Harry Potter?",
choices: ["Melisandre", "Alerie Tyrell"],
answer: "Melisandre",
image:
"https://media.gettyimages.com/photos/beautiful-book-picture-id865109088?s=612x612"
},
{
question:
'Who said, "You knelt as boys, now rise as men of the Nights Watch."?',
choices: [
"Maester Aemon",
"Eddard Stark",
"Jeor Mormont",
"Alliser Thorne"
],
answer: "Maester Aemon",
image: "https://tinypng.com/images/social/website.jpg"
},
{
question: "Who built the Iron Throne?",
choices: [
"Aerys the Mad King",
"Aegon The Unlikely",
"Aegon the Conqueror",
"Aegon the Destroyer"
],
answer: 2,
image: ""
},
{
question: "Which knight takes a lance through the neck while jousting?",
choices: [
"Ser Hugh of the Vale",
"Ser Barristan Selmy",
"Ser Ilyn Payne",
"Ser Gregor Clegane"
],
answer: 0,
image: ""
},
{
question: "What does Valar Morghulis mean?",
choices: [
"All men must die",
"What is dead may never die",
"Never say never",
"All men must first live",
"Robb Stark",
"Jon Snow",
"Theon Greyjoy"
],
answer: "All men must die",
image:
"https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
},
{
question:
"Which GOT character played Hermoine Granger's mom in Harry Potter?",
choices: ["Melisandre", "Alerie Tyrell"],
answer: "Melisandre",
image:
"https://media.gettyimages.com/photos/beautiful-book-picture-id865109088?s=612x612"
},
{
question:
'Who said, "You knelt as boys, now rise as men of the Nights Watch."?',
choices: [
"Maester Aemon",
"Eddard Stark",
"Jeor Mormont",
"Alliser Thorne"
],
answer: "Maester Aemon",
image: "https://tinypng.com/images/social/website.jpg"
},
{
question: "What does Valar Morghulis mean?",
choices: [
"All men must die",
"What is dead may never die",
"Never say never",
"All men must first live",
"Robb Stark",
"Jon Snow",
"Theon Greyjoy"
],
answer: "All men must die",
image:
"https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
},
{
question:
"Which GOT character played Hermoine Granger's mom in Harry Potter?",
choices: ["Melisandre", "Alerie Tyrell"],
answer: "Melisandre",
image:
"https://media.gettyimages.com/photos/beautiful-book-picture-id865109088?s=612x612"
},
{
question:
'Who said, "You knelt as boys, now rise as men of the Nights Watch."?',
choices: [
"Maester Aemon",
"Eddard Stark",
"Jeor Mormont",
"Alliser Thorne"
],
answer: "Maester Aemon",
image: "https://tinypng.com/images/social/website.jpg"
}
];
let pageInfo = {
curr: 0,
page: 0,
limit: 10,
total: allQuestions.length
};
const PAGE_COUNT = Math.round(pageInfo.total / pageInfo.limit - 1);
const onNext = () => {
pageInfo.curr = pageInfo.curr + 1;
if (pageInfo.curr >= pageInfo.limit) {
pageInfo.page = pageInfo.page + 1;
pageInfo.curr = pageInfo.curr - 10;
if (pageInfo.page > PAGE_COUNT) {
pageInfo.page = 0;
pageInfo.curr = 0;
}
}
console.log(pageInfo);
};
const onPrev = () => {
pageInfo.curr = pageInfo.curr - 1;
if (pageInfo.curr < 0) {
pageInfo.curr = pageInfo.limit - 1;
pageInfo.page = pageInfo.page - 1;
if (pageInfo.page < 0) {
pageInfo.page = PAGE_COUNT;
}
}
console.log(pageInfo);
};
const onPageNext = () => {
pageInfo.page = pageInfo.page + 1;
if (pageInfo.page > PAGE_COUNT) {
pageInfo.page = 0;
pageInfo.curr = 0;
}
console.log(pageInfo);
};
const onPagePrev = () => {
pageInfo.page = pageInfo.page - 1;
if (pageInfo.page < 0) {
pageInfo.page = PAGE_COUNT;
}
console.log(pageInfo);
};
const fetctData = () => {
const curr = pageInfo.page * pageInfo.limit;
return allQuestions.slice(curr, curr + 10);
};
onNext();
console.log(pageInfo);
onPrev();
console.log(pageInfo);
onNext();
onNext();
onNext();
onNext();
onNext();
console.log(pageInfo);
onNext();
onNext();
console.log(pageInfo);
onNext();
console.log(pageInfo, fetctData());
onPageNext();
console.log(pageInfo, fetctData());
onPagePrev();
console.log(pageInfo, fetctData());
关于javascript - 如何在单击下一个隐藏上一个10并显示新的jquery后拆分所有元素li以显示10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60209003/
我遇到了一个奇怪的问题。我的应用程序的 Release 版本似乎运行良好,但最近当我切换到 Debug 版本时,我在启动时立即遇到访问冲突。当释放分配的内存块时,就会发生访问冲突。所有这些都发生在静态
我在 C# 中偶然发现了这种奇怪的语法形式,并试图弄清楚它的含义以及如何使用它。网络上似乎没有关于此的任何文档。 object data = new { var1 = someValue, var2
我正在尝试使用浏览器的内置类型 CSSStyleDeclaration 以编程方式传递和修改样式(由于 .cssText 属性,这很方便)。 但是,new CSSStyleDeclaration()
我有现成的代码: internal bool firstAsSymbol(out Symbol s) { return (s = first as Symbol) !=
在新的 Eclipse 版本 2022-03 中,一些(但不是全部)java 项目在 Project Explorer View 中的外观发生了变化。尽管 Package Presentation 设
我正在尝试使用 FormData 通过获取 API 在 POST 请求中发送用户输入的数据。问题是,当我用我创建的表单创建一个新的 FormData 对象时,它一直在创建一个空对象——没有条目/键/值
我有一个用一些 intel-intrinsincs 编写的 C 代码。在我先用 avx 然后用 ssse3 标志编译后,我得到了两个完全不同的汇编代码。例如: AVX: vpunpckhbw %xm
最近,discord 为您自己的应用程序添加了对斜杠命令的支持。我通读了它的文档,并尝试搜索一些视频(但是该功能刚刚出现),但我不明白我实际上需要做什么才能使其正常工作。我正在使用 WebStorm(
我想使用 JRI 从 Java 调用 R。 我在 eclipse 下在主类中运行它: Rengine c = new Rengine(new String[] { "--vanilla" },
我正在使用新的 Place Autocomplete那是来自新的静态Google Places SDK 客户端库 (here)。所以它真的很容易使用,我刚得到this tutorial它按预期工作。
我刚刚更新到 flutter 版本 1.25.0-5.0.pre.92,我的代码中出现了很多与空安全相关的错误,这些错误以前运行良好。我没有以任何方式选择空安全,我所做的只是运行 flutter 升级
我已经使用 React Native 有一段时间了,但我想我会在网络上试用 React。所以我遵循了这个指南:https://reactjs.org/docs/create-a-new-react-a
周六早上在这里。尝试学习新的 Scala 编译器 dotty。 安装在我的 Mac 上使用 brew install lampepfl/brew/dotty 安装成功。我有版本 dotr -versi
我使用了谷歌地方的新依赖。单击自动完成 View 时应用程序崩溃。错误如下。, java.lang.NullPointerException: Place Fields must be set.
我关注了这个博客-> https://medium.com/@teyou21/training-your-object-detection-model-on-tensorflow-part-2-e9e
在哪里可以找到用于在此架构上进行组装的新寄存器的名称? 我指的是 X86 中的寄存器,如 EAX、ESP、EBX 等。但我希望它们是 64 位的。 我认为它们与我反汇编 C 代码时不同,我得到的是 r
新的服务总线库 Azure.Messaging.ServiceBus 使用 ServiceBusReceivedMessage 来接收消息 https://learn.microsoft.com/en
需要使用实时流媒体 channel 的实时编码类型在新的 Azure 门户中配置广告插入和石板图像。请帮忙解决这个问题,因为我找不到该功能。 最佳答案 此处描述了 Azure 媒体服务的广告插入选项
我正在使用新的 GitHub 操作,下面的工作流程的想法是在打开或同步 pr 时运行,它应该首先检查并安装依赖项,然后运行一些 yarn 脚本 name: PR to Master on: pul
我听说 DMD 2.058 中将有一个用于匿名函数的新语法,但我找不到任何相关信息。新语法是什么?旧语法是否会被弃用? 最佳答案 我相信它就像 C#'s . 以下内容是等效的: delegate(i,
我是一名优秀的程序员,十分优秀!