我需要创建一个表单,允许用户输入问题的答案,并输入他们需要输入的答案[Cat,Rabbit,Cow,Bull,Dog]。如果他们得到了正确的答案,JQuery应该返回一个启动箱对话框,让他们知道他们已经通过下一个问题的链接回答了问题。
我在下面提供了表格:
{% block main %}
<form name="answer" id="uanswer" method="get">
<input type="text" id="answer" name="answer" placeholder="Enter Your Answer Here" style="text-align: center; width: 300px;">
<input type="button" value="Check My Answer" id="useranswer">
</form>
{% endblock main %}
这是我的JQuery:
{% block onload %}
$("#useranswer").on("submit", function(event) {
event.preventDefault();
answer = $("#answer").val();
if (answer.toLowerCase() == "[cat, rabbit, cow, bull, dog]"){
bootbox.dialog({
closeButton: false,
onEscape: false,
title: "<h1>That's Correct!</h1>",
message: "Notice in a hashSet that the data in the set is in the same order that it is added in. Now lets move onto TreeSets",
buttons: {
success:{
label: "Next Question",
callback: function(result) {
if (result) {
window.location.href = 'http://localhost/webproject/stude/exampletest3/';
}
}
}
}
})
} else {
bootbox.alert("That's Incorrect!")
}
});
{% endblock onload %}
然而,当我按下提交按钮时,页面上根本没有任何事情发生,我不确定为什么。
答案 0 :(得分:0)
$(&#39; #useranswer&#39;)是一个按钮,因此您应该编写点击而不是提交事件,如下所示:
$("#useranswer").on("click", function(event) {