gpt4 book ai didi

javascript - 如果函数返回相同的输出

转载 作者:行者123 更新时间:2023-11-30 13:06:46 25 4
gpt4 key购买 nike

当用户选择一个答案时,下面的代码应该给出不同的结果;但是,它只是给出了相同的结果。为什么按下按钮时会给出相同的结果?

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>

最佳答案

   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....";
}

关于javascript - 如果函数返回相同的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15394750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com