简体   繁体   English

当我添加更多问题(JS)时测验消失,怎么办?

[英]Quiz disappears when I add more questions (JS), how?

I found a pen online, a quiz, which I could use. 我在网上找到了一支笔,可以用来测验。 So I edited it and so. 所以我编辑了它等等。

This is the JS that still works, the quiz answers will still appear on the website 这是仍然有效的JS,测验答案仍将出现在网站上

https://jsfiddle.net/ptkrngza/2/

(in this Fiddle it is still not working :( So that's weird, but it is actually working in Coda/My browser, and I suppose it's really all about the Javascript right?) But if it helps, this is the original codepen (在这个小提琴中,它仍然不起作用:(太奇怪了,但是它实际上可以在Coda /我的浏览器中工作,而且我想这实际上与Javascript有关吗?)但是,如果有帮助,这就是原始的代码笔

https://codepen.io/nicklemmon/full/LpZKBO

en this is a Fiddle with the JS, that is not working. zh_cn这是JS的提琴,无法正常工作。

jsfiddle.net/k0ns63a9/

So it's all about the js i think? 所以这就是我想的js吗? Whenever I put in 4 questions, it just works. 每当我提出4个问题时,它都会起作用。 But when I add more questions, in the browser the questions/answers just disappear. 但是,当我添加更多问题时,在浏览器中问题/答案就消失了。 But what do I have to change on the js so that the quiz still works properly (but with more questions)? 但是我必须在js上进行哪些更改,以便测验仍然可以正常工作(但还有更多问题)?

I can't really figure it out on my own unfortunately 不幸的是我无法真正解决这个问题

Thanks!! 谢谢!! If more info is needed I am more than willing to give them to you. 如果需要更多信息,我非常愿意将它们提供给您。 Although I think someone good in javascript will figure it out pretty quick :p 虽然我认为擅长javascript的人会很快解决它:p

Thank you! 谢谢!

Edit: so the question is basically: what do I have to edit on the JS of that Codepen so that I can add more questions to the quiz en the JS/Website will still work properly 编辑:所以问题基本上是:我必须在那个Codepen的JS上进行哪些编辑,以便我可以向测验中添加更多问题,以便JS /网站仍然可以正常工作

There are two problems: your array elements are missing the separating commas, and jQuery isn't being loaded. 有两个问题:数组元素缺少分隔的逗号,并且jQuery未加载。

I found this by using the browser's developer tools window. 我是通过浏览器的开发人员工具窗口找到的。 (F12 in Chrome or Hamburger menu > More tools > Developer tools). (Chrome或Hamburger菜单中的F12>更多工具>开发人员工具)。

1) I changed the focus to be the results pane 1) 我将焦点更改为结果窗格

2) Running the code we can see three errors . 2) 运行代码,我们可以看到三个错误 The first is because the Javascript interpreter expects a comma between array elements. 第一个是因为Javascript解释器期望数组元素之间使用逗号。 Fix that first. 首先解决该问题。

3) After fixing the commas we can see that it can't find the scripts you've specified at the end of your HTML, and that jQuery isn't being loaded. 3) 修复逗号后,我们可以看到它找不到您在HTML末尾指定的脚本,并且未加载jQuery。 If we look at the CodePen, we can see that they're loading jQuery as an external script. 如果我们看一下CodePen,我们可以看到他们正在将jQuery作为外部脚本加载。 We need to do the same in JSFiddle. 我们需要在JSFiddle中执行相同的操作。 Add a jQuery CDN URL, like this , paste it in and done . 添加一个jQuery CDN URL,将粘贴并完成

Runs perfectly now! 现在运行完美!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM