我是Javascript和Jquery中的新成员,所以出现问题。Javascript条件 - 如果复选框条件为true,则显示元素
这是一个代码,用于检查是否选中了三个复选框,最后 - 条件 - 如果所有这三个选项都被选中,则显示一个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"); }
});
我想问题是在设置变量或在最后一个条件。
提前致谢! 最好的问候, 乔尼
'如果(questionOne = 1 ...' - 使用'='* *分配值1到可变要* *试验该值使用'==='或'=='。 – nnnnnn