如何在Jquery中添加else语句?

How can I add an else statement to this Jquery?

本文关键字:else 语句 添加 Jquery      更新时间:2023-09-26
$(document).ready(function(){
$("#start_quiz").click(function(){
    $("#start_quiz").fadeOut(0);
    $("#quiz_game").fadeIn('slow');
    $("#answer_button").click(function(){
        if($("#test").is(":checked")){
            $(".questions").fadeOut(200, function(){
                $('#correct_answer').fadeIn('slow');
            });
        };
    });
});
});

我已经设法让这个jQuery代码工作,这样,如果正确的答案是在我的形式,它会淡出并显示一些文本。我想知道我如何设计这个,所以如果其他四个单选按钮被按下,它可以显示其他文本(目前什么都没有发生)。谢谢你的帮助。

$(document).ready(function () {
    $("#start_quiz").click(function () {
        $("#start_quiz").fadeOut(0);
        $("#quiz_game").fadeIn('slow');
        $("#answer_button").click(function () {
            if ($("#test").is(":checked")) {
                $(".questions").fadeOut(200, function () {
                    $('#correct_answer').fadeIn('slow');
                });
            } else {
                /* YOU WOULD PUT CODE HERE FOR INCORRECT ANSWER */
            }
        });
    });
});
http://jsfiddle.net/24DeT/

if($("#test").is(":checked")){
            $(".questions").fadeOut(200, function(){
                $('#correct_answer').fadeIn('slow');
            });
}
else if($("#testotherone").is(":checked")){
            $(".questions").fadeOut(200, function(){
                $('#otherone_answer').fadeIn('slow');
            });
}
else if($("#testothertow").is(":checked")){
            $(".questions").fadeOut(200, function(){
                $('#othertow_answer').fadeIn('slow');
            });
}