使用输入按钮检查用户无线电输入以返回bootbox

时间:2018-03-14 17:58:48

标签: jquery html twig

我有一个带有无线电列表的表单,用户必须在这里选择正确的答案,用户将点击一个提交按钮,检查他们选择了哪个无线电并返回一个启动箱,通知他们是否选择了正确的答案在将它们移到下一个问题之前。

JQuery的:

{% block onload %}
    $("#useranswer").on("click", function(event){

    var answer = $('[name="answer"]:checked).val();

    if (answer == "answer1") {
        bootbox.dialog({
            closeButton: false,
            onEscape: false,
            title: "the title",
            message: "the message",
            buttons: {
                success:{
                    label: "Next Question",
                    callback: function(result) {
                        if (result) {
                            window.location.href = 'http://localhost/webproject/java/tutorialone.questionfour/';
                        }
                    }
                }
            }
        })
    }
    });
{% endblock onload %}

HTML /枝条:

{% block main %}
    <section class="row">
        <article class="ml-auto col-md-8 mr-auto">
            <p>Which print method is used in a Java program to print on a new line?</p>
            <br><br>
            <form id="uanswer" method="get">
                <input type="radio" name="answer" value="answer1" id="answer1"> System.out.println()<br><br>
                <input type="radio" name="answer" value="answer2" id="answer2"> Console.WriteLine<br><br>
                <input type="radio" name="answer" value="answer3" id="answer3"> printf()<br><br>
                <input type="radio" name="answer" value="answer4" id="answer4"> System.out.ln()<br><br>
                <input type="button" value="Check My Answer" id="useranswer" class="btn btn-large btn-info">
            </form>
        </article>
    </section>
{% endblock main %}

我不确定如何使这项工作。

1 个答案:

答案 0 :(得分:0)

我错过了我的var声明中的'

var answer = $('[name="answer"]:checked').val();