当用户选择答案时,下面的代码应该给出不同的结果;但是,它只是给出了相同的结果。按下按钮时为什么会给出相同的结果?
1.Is the network problem affecting just your pc? <BR>
<select id="Area">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br>
<br><p>
2.Can you access the internet? <BR>
<select id="Internet">
<option value="Yes">Yes</option>
<option value="No">No</option>
<option value="Yes,but is slow">Yes,but is slow</option>
<option value="Drop in connection">Drop in connection</option>
</select>
<br>
<br><p>
3.Are you receiving any error message saying remote system could not be found or connection has timed out?<BR>
<select id="Errors">
<option value="Remote">Remote system could not be found</option>
<option value="Connection">Connection has timed out</option>
<option value="No">No error messages </option>
</select>
<br>
<br><p>
4.Have you changed any software or Hardware before the problem occurred?<BR>
<select id="Change">
<option value="Software">Software</option>
<option value="Hardware">Hardware</option>
<option value="Both">Both</option>
<option value="None">None </option>
</select>
<br>
<br><p>
<button onclick="myFunction()">Detect</button>
<p id="Solution"></p>
<script>
function myFunction()
{
var AreaElem = document.getElementById("Area");
var Area = AreaElem.options[AreaElem.selectedIndex].value;
var InternetElem = document.getElementById("Internet");
var Internet= InternetElem.options[InternetElem.selectedIndex].value;
var ErrorsElem = document.getElementById("Errors");
var Errors= ErrorsElem.options[ErrorsElem.selectedIndex].value;
var ChangeElem = document.getElementById("Change");
var Change= ChangeElem.options[ChangeElem.selectedIndex].value;
if (Area=="Yes"||Internet=="Yes"||Errors=="No"||Change=="No") {
x="check your cable is not cut or loose";
} else if (Area=="Yes"||Internet=="Yes"||Errors=="No"||Change=="Both") {
x="network connections ";
} else {
x="other problems....";
}
document.getElementById("Solution").innerHTML=x;
}
</script>
答案 0 :(得分:3)
if (Area=="Yes"||Internet=="Yes"||Errors=="No"||Change=="No") {
x="check your cable is not cut or loose";
} else if (Area=="Yes"||Internet=="Yes"||Errors=="No"||Change=="Both") {
x="network connections ";
} else {
x="other problems....";
}
问题出在这里!您正在使用“或”运算符||
,您应该使用“和”运算符&&
这应该解决它
if (Area=="Yes"&&Internet=="Yes"&&Errors=="No"&&Change=="No") {
x="check your cable is not cut or loose";
} else if (Area=="Yes"&&Internet=="Yes"&&Errors=="No"&&Change=="Both") {
x="network connections ";
} else {
x="other problems....";
}