Javascript条件-如果复选框条件为true,则显示元素

Javascript条件-如果复选框条件为true,则显示元素,javascript,jquery,if-statement,conditional-statements,Javascript,Jquery,If Statement,Conditional Statements,我是Javascript和Jquery新手,所以我遇到了一个问题 下面是一段代码,它检查是否选中了三个复选框,最后-条件-如果这三个复选框都选中,则显示一个html元素 $('input[class^="class"]').click(function() { var $this = $(this); if ($this.is(".class1")) { if ($this.is(":checked")) { $(".class1").no

我是Javascript和Jquery新手,所以我遇到了一个问题

下面是一段代码,它检查是否选中了三个复选框,最后-条件-如果这三个复选框都选中,则显示一个html元素

$('input[class^="class"]').click(function() {    var $this = $(this); 
    if ($this.is(".class1")) {
        if ($this.is(":checked")) {
            $(".class1").not($this).prop({ disabled: true, checked: false });
            $(".class").prop("checked", true);
            setTimeout(function() { $('#2').click(); }, 1000); //oncheck moves to the next question
            var questionOne = 1;
        } else {
            $(".class1").prop("disabled", false);
        }
    }

   if($this.is(".class2")) {
        if ($this.is(":checked")) {
            $(".class2").not($this).prop({ disabled: true, checked: false });
            $(".class").prop("checked", true);
            setTimeout(function() { $('#3').click(); }, 1000);
            var questionTwo = 1;
        } else {
            $(".class2").prop("disabled", false);
        }
    }

   if($this.is(".class3")) {
        if ($this.is(":checked")) {
            $(".class3").not($this).prop({ disabled: true, checked: false });
            $(".class").prop("checked", true);
            setTimeout(function() { $('#4').click(); }, 1000);
            var questionThree = 1;
        } else {
            $(".class3").prop("disabled", false);
        }
    }

 if(questionOne = 1 && questionTwo = 1 && questionThree = 1) { alert("alert on Page load"); }                                             
}); 
我想问题不是在于设置变量,就是在于最后一个条件

提前谢谢! 顺致敬意,
Joni

将您最后的状况检查更改为:

if(questionOne === 1 && questionTwo === 1 && questionThree === 1) { 
    alert("alert on Page load"); 
}   

您可以在

上获得有关javascript比较的一些基本知识,将您的最后一个条件检查更改为:

if(questionOne === 1 && questionTwo === 1 && questionThree === 1) { 
    alert("alert on Page load"); 
}   

你可以在

Bro上获得一些关于javascript比较的基本知识,你的意思是这样吗

HTML:


兄弟,你是说那样吗

HTML:


if(questionOne=1…
-使用
=
将值1分配给变量。要测试该值,请使用
==
=
if(问题一=1…-使用
=
将值1分配给变量。要测试值,请使用
==
=
。是的,非常感谢,这正是我需要的。是的,非常感谢,这正是我需要的。
$(document).ready(function(){
    var  checkAndShow = function (){
        return ($('.check1').is(':checked')&&$('.check2').is(':checked')&&$('.check3').is(':checked'));
    }

    $('.check1,.check2,.check3').on('change', function(e){
        if(checkAndShow()){
            //show your div here
        }
        else{
            //hide your div here
        }
    });
});