当我更改所需的输出时,Javascript停止工作

时间:2016-02-18 15:07:05

标签: javascript

//THIS CODE WORKS PERFECTLY, IT PLACES A RECOMMENDATION IN A DIV            (Suggestion) BASED ON LIGHT STATUS 

function getIntLght(){
  var textIntLght = document.getElementById("selIntLght").value;
  var textDSL = document.getElementById("selDSL").value;
  document.getElementById("intLght").innerHTML= "Internet light Status: " + textIntLght;

  //recommend if trouble shooting script based on light status of DSL and Internet
  if(textDSL=="Flashing/Off"){
     document.getElementById("suggestion").innerHTML= "Consider NO Sync";
  } else if (textDSL =="Solid" && (textIntLght=="Red/Amber" || textIntLght=="Off")){
    document.getElementById("suggestion").innerHTML= "Consider NO ROUTE";
  } else {
    document.getElementById("suggestion").innerHTML="Consider WALLED GARDEN OR CONNECT NO BROWSE";
  } 
}


// TRYING TO MAKE CORRESPONDING DIV OPEN INSTEAD OF JUST POPULATING THE SUGGESTION DIV- BROKEN, DOES NOT WORK   
// "if" works, but not "if else" or "else", even though the logic is the same as above and works there. 

function getIntLght(){
  var textIntLght = document.getElementById("selIntLght").value;
  var textDSL = document.getElementById("selDSL").value;
  document.getElementById("intLght").innerHTML= "Internet light Status: " + textIntLght;

  //recommend if trouble shooting script based on light status of DSL and Internet
  if(textDSL=="Flashing/Off") {
    document.getElementById("noSync").style.display="block"; 
    document.getElementById("noRoute").style.display="none";
    document.getElementById("CNB").style.display="none";
  } else if (textDSL =="Solid" && (textIntLght=="Red/Amber" || textIntLght=="Off")){
    document.getElementById("noRoute").style.display="block";
    document.getElementById("noSync").style.display="none"; 
    document.getElementById("CNB").style.display="none";
  } else {
    document.getElementById("CNB").style.display="block";
    document.getElementById("noSync").style.display="none";
    document.getElementById("noRoute").style.display="none";
  } 
}

如果你看到我遗失的内容,请告诉我......我找不到我的错误 我确实纠正了.style.display中的拼写错误,但它仍然无效。 感谢您指出这一点,但有些事情仍然是错误的。

2 个答案:

答案 0 :(得分:1)

您有一些拼写错误,sytle而不是style

答案 1 :(得分:0)

您是否尝试使用===作为if / else if语句? This link explains the difference between == and ===.

<html>
<body>

<input type="text" id="selIntLght"/>
<input type="text" id="selDSL"/>
<button onclick="getIntLght()">submit</button>

<div id="intLght"></div>
<div id="suggestion"></div>

<div id="noSync" style="display:none">No sync</div>
<div id="noRoute" style="display:none">No Route</div>
<div id="CNB" style="display:none">CNB</div>


<script>

function getIntLght(){
    var textIntLght = document.getElementById("selIntLght").value;
    var textDSL = document.getElementById("selDSL").value;
    document.getElementById("intLght").innerHTML= "Internet light Status: " + textIntLght;

//hide divs initially
document.getElementById("CNB").style.display="none";
document.getElementById("noSync").style.display="none";
document.getElementById("noRoute").style.display="none";

//recommend if trouble shooting script based on light status of DSL and Internet
if(textDSL==="Flashing/Off"){
    document.getElementById("suggestion").innerHTML= "Consider NO Sync";
    document.getElementById("noSync").style.display="block"; 
} else if (textDSL =="Solid" && (textIntLght=="Red/Amber" || textIntLght=="Off")){
    document.getElementById("suggestion").innerHTML= "Consider NO ROUTE";
    document.getElementById("noRoute").style.display="block";
} else {
    document.getElementById("suggestion").innerHTML="Consider WALLED GARDEN   OR     CONNECT NO BROWSE";
    document.getElementById("CNB").style.display="block";
} 
}

</script>
<html>