我正在运行基于HTML + JavaScript的页面。
这是我的代码:
<script type="text/javascript">
/*var test = "Hello";
document.getElementById("mytext").value = test;
*/
function myFunction() {
var resultado;
var c1 = document.getElementById("mySelect").value;
var c2 = document.getElementById("mySelect2").value;
var c3 = document.getElementById("mySelect3").value;
if(c1 == "nao" , c2 == "nao" , c3 == "nao" ){
resultado = 1;
}
else if(c1 == "nao" , c2 == "nao" , c3 == "sim" ){
resultado = 2;
}
else if
(c1 == "nao" , c2 == "sim" , c3 == "sim" ){
resultado = 3;
}
else {
resultado = 4;
}
document.getElementById("demo").innerHTML = resultado;
}
</script>
</script>
<form action="fb.php" method="POST">
<select name="test" id="mySelect" onchange="myFunction()">
<option value="selecione">selecione...</option>
<option value="sim">sim</option>
<option value="nao">nao</option>
<option value="jim">jim</option>
</select>
<select name="test" id="mySelect2" onchange="myFunction()">
<option value="selecione">selecione...</option>
<option value="sim">sim</option>
<option value="nao">nao</option>
</select>
<select name="test" id="mySelect3" onchange="myFunction()">
<option value="selecione">selecione...</option>
<option value="sim">sim</option>
<option value="nao">nao</option>
</select>
<p id="demo"></p>
</body>
</html>
第一个条件返回
1
,这很好。但是,第三个条件
(c1 == "nao" , c2 == "sim" , c3 == "sim")
始终返回2。我有个小提琴:https://jsfiddle.net/qoL6e0ca/
有人可以帮我吗?
最佳答案
iF
语句的Anding与&&
一样使用if(c1 == "nao" && c2 == "nao" && c3 == "sim" )