JQuery使用对象进行过滤
我很难让我的测验起作用。我试着用第一个问题的前两个答案[0,1]来结束测验,并将它们发送到一个特定的部门,该部门将向他们展示更多关于婚礼/教学的信息。我试着将输入字段与回答进行比较,但它继续过滤掉剩下的问题,这是我不想要的。我是新来的,我看不出我的错误,任何帮助都将被感激JQuery使用对象进行过滤,jquery,arrays,object,Jquery,Arrays,Object,我很难让我的测验起作用。我试着用第一个问题的前两个答案[0,1]来结束测验,并将它们发送到一个特定的部门,该部门将向他们展示更多关于婚礼/教学的信息。我试着将输入字段与回答进行比较,但它继续过滤掉剩下的问题,这是我不想要的。我是新来的,我看不出我的错误,任何帮助都将被感激 测验 下一个 重新开始 //所有的问题和答案 变量问题=[{ 问题:“告诉我们一些关于你自己的情况……”, 选择:[ “我是一名教师”、“我要结婚”、“我还在上学”、“我是一名忙碌的专业人士”, “我是个计划书呆子”,“
测验
下一个
重新开始
//所有的问题和答案
变量问题=[{
问题:“告诉我们一些关于你自己的情况……”,
选择:[
“我是一名教师”、“我要结婚”、“我还在上学”、“我是一名忙碌的专业人士”,
“我是个计划书呆子”,“我随波逐流”,“我喜欢旅行”
],
答复:[“0”、“1”]
}, {
问题:“你想要日历吗?”,
选择:[“是的,我想要日历!”,“不,我不想要日历。”,
}, {
问题:“你说你想要一个日历。你想用你的书做什么?”,
选择:[我想用它来保持记忆——即使我没有时间表,我仍然会把事情写下来。”,“我想记录我的日常活动和一小时一小时的时间表。”,“我想把我家人的时间表放在一个地方。”,“我想每月计划一次重大的事情,但详细的计划包括更多的笔记和清单。”,“我想跟踪项目、任务和笔记。”,“我想管理预算并掌握一切。”,“我想以项目符号格式记录我的日常任务、事件和每日笔记。”,”我想以长格式详细记录我的任务、事件和每日笔记。”,“我想在外出时写下我的想法、想法和笔记。”,“实际上,我不想要日历。”]
}, {
问题:“你说你不想要日历。你想怎么处理你的书?”,
选择:[“用我的激情填满书页”,“记笔记并处理我的任务”,“让我的创造力流动起来!”,“事实上,我真的想要一个日历。”]
}, {
问题:“你的规划风格是什么?”,
选择:[“这里有一个额外的回复?”,“详细的:我需要一个大事情的月视图和一个我每天按小时计划的周视图。”,“分类的:我将每天分成一个类别(例如工作、个人、家庭),以便清楚地了解我的目标。”目标导向:我的日程安排得很好,所以我只需写下当天需要做的几件重要事情的提醒。”,“任务驱动:我需要计划好我的月份,安排好我的周数,并有一个专门的项目/任务部分,这样我就可以完成工作。”,”任务驱动:我每个月都计划大事,但我喜欢在笔记中分解特殊项目、想法和任务。”,“创意:我需要一个定制的创意空间来整理我的想法并以我的风格计划事情,并有足够的空间放置嵌入式配件。”,“在路上:我只需要一些漂亮的便携式东西,可以放在我的包里快速记笔记。”]
}];
$(“#重置”).hide();//将“重新开始”按钮隐藏到结束
$(“.message”).hide();//隐藏消息div
var currentQuestion=0;//跟踪问题
$('.teacher').hide();
$('.wedding').hide();//仅在筛选出第一个问题时显示。
var questionSpecific=问题[currentQuestion]。选择;
函数displayCurrentQuestion(){
var问题=问题[currentQuestion]。问题;
var questionClass=$(“.question”);
var choiceList=$(“.choiceList”);
var numChoices=questions[currentQuestion].choices.length;
//这项质询已列入质询组。
$(问题类)。文本(问题);
//从前面的问题中删除所有当前元素
$(choiceList.find(“div”).remove();
var选择;
对于(i=0;i
看起来您的代码中有一些语法错误;您的控制台中有任何错误吗?没有,控制台上没有弹出任何错误。
<div class="quiz-holder">
<p>QUIZ</p>
<h3><div class="question"></div></h3>
<strong><div class="message"></div></strong>
<div class="choiceList"></div>
<button class="nextButton">Next</button>
<button id="reset">Start over</button>
</div>
<div class="teacher">
</div>
<div class="wedding">
</div>
//all the questions and answers
var questions = [{
question: "Tell us a little about yourself...",
choices: [
"I'm a teacher", "I'm getting married", "I'm still in school ", "I'm a busy professional",
"I'm a planner nerd", "I go with the flow", "I love traveling"
],
response: ["0", "1"]
}, {
question: "Do you want a calendar?",
choices: ["Yes, I want a calendar!", "No, I don't want a calendar."],
}, {
question: "You said you would like a calendar. What would you like to do with your book?",
choices: ["I want to use it for memory keeping - even if I don't have a schedule to manage, I still write things down.", "I want to keep track of my routines & schedule hour by hour.", "I want to keep my family's schedule in one place.", "I want to plan out the big things on a monthly spread, but the detailed planning consists more of notes & lists.", "I want to keep track of projects, assignments, and notes.", "I want to manage a budget and stay on top of everything.", "I want to log my daily tasks, events and daily notes in bullet format.", "I want to keep a detailed log my tasks, events, and daily notes in long-form format.", "I want to write down my ideas, thoughts & notes while out and about.", "Actually, I don't want a calendar."]
}, {
question: "You said you do not want a calendar. What would you like to do with your book?",
choices: ["Fill up the pages with my passions", "Take notes & tackle my tasks", "Let my creativity flow!", "Actually, I really do want a calendar."]
}, {
question: "What's your planning style?",
choices: ["an extra response here?", "Detailed: I need a monthly view for the big things and a weekly view where I plan each day by the hour.", "Categorized: I separate each day into a category (work, personal, home, for example) to have a clear view of my goals.", "Goal Oriented: My schedule's pretty set so I just write down reminders for the few important things I need to do that day.", "Assignment Driven: I need to plan out my month, schedule my weeks and have a dedicated project/assignment section so I can get things done.", "Task Driven: I plan the big things month by month but I like to break down special projects, ideas & tasks in my notes.", "Creative: I need a customized creative space to sort my thoughts and plan things in my style with plenty of room for snap-in accessories.", "On-The-Go: I just need something pretty & portable that fits in my bag for quick notes."]
}];
$("#reset").hide(); //to hide the start over button until the end
$(".message").hide(); //to hide message div
var currentQuestion = 0; //keeps track of the question
$('.teacher').hide();
$('.wedding').hide();//only to be shown when the first question is filtered out.
var questionSpecific = questions[currentQuestion].choices;
function displayCurrentQuestion() {
var question = questions[currentQuestion].question;
var questionClass = $(".question");
var choiceList = $(".choiceList");
var numChoices = questions[currentQuestion].choices.length;
// the question is put into the question div.
$(questionClass).text(question);
// Remove all current <div> elements from previous questions
$(choiceList).find("div").remove();
var choice;
for (i = 0; i < numChoices; i++) {
choice = questions[currentQuestion].choices[i];
$("<div><input type='radio' value=" + i + " name='input'>" + choice + "</div>").appendTo(choiceList);
}
}
$(document).ready(function() {
// Display the first question
displayCurrentQuestion();
$(".message").hide();
// On clicking next, display the next question
$(".nextButton").on("click", function() {
value = $("input:checked").val();
if (value === undefined) {
$(".message").text("Please select an answer").css('color', 'red');
$(".message").show();
} else {
$(".message").hide();
currentQuestion++;
if (currentQuestion < questions.length) {
displayCurrentQuestion();
}};
if (value === questions[0].response[0]) {
console.log('why isnt this working?');
};
if (value === questions[0].response[1]) {
console.log('WHY!?');
};
});
});