2013-03-04 29 views
-5

我想製作一個專家系統來檢測網絡問題。用戶將有4個問題,每個問題有3到4個答案。在用戶輸入之後,用戶將點擊按鈕,它將檢測並解決問題。我有點想法,但我知道有幾件事情不見了。目前,我只添加了2個隨機問題和答案,以檢查是否實際工作。請幫助使用java腳本,因此它會根據答案給出有關網絡問題的詳細信息。提前致謝! :)如果在使用JavaScript的下拉列表中的功能

1.Can you access to the internet? <BR> 

<select id="internet"> 

    <option value="yes">yes</option> 

    <option value="No">no</option> 

    <option value="Yes, but at slow">Yes, but at slow</option> 

    <option value="Yes/No, it workes but it suddenly it stops and start working again ">Yes/No, it workes but it suddenly it stops and start working again</option> 

</select> 

<br> 

<br><p> 


2.Is it just your computer?<BR> 



<select id="computer"> 

    <option value="yes">yes</option> 

    <option value="whole company">whole company</option> 

    <option value="just my department">just my department</option> 

    <option value="me and few staff">me and few staff</option> 

</select> 

<br> 

<br><p> 




<button onclick="myFunction()">Detect</button> 

<p id="Solution"></p> 

<script> 
function myFunction() 
{ 

if (internet=="no"||computer=="yes") 
  { 
  x="check your cable is not cut or loose"; 
  } 
else if (internet=="no"||computer=="yes") 
  { 
  x="connection problem"; 
  } 
else 
  { 
  x="other problems...."; 
  } 
document.getElementById("Solution").innerHTML=x; 
} 
</script> 
+3

所以......你是什麼題? – Doorknob 2013-03-04 16:53:11

+0

這裏有什麼問題? – DevelopmentIsMyPassion 2013-03-04 16:54:15

+0

不工作,我是新的Java腳本。如果我選擇任何答案,它只會給出相同的輸出。 – 2013-03-04 16:56:34

回答

0
function myFunction() 
{ 
    var internetElem = document.getElementById("internet"); 
    var internet = internetElem.options[internetElem.selectedIndex].value; 
    var computerElem = document.getElementById("computer"); 
    var computer= internetElem.options[internetElem.selectedIndex].value; 

    if (internet=="no"||computer=="yes") { 
     x="check your cable is not cut or loose"; 
    } else if (internet=="no"||computer=="yes") { 
     x="connection problem"; 
    } else { 
     x="other problems...."; 
    } 
    document.getElementById("Solution").innerHTML=x; 
} 

你需要這樣的東西上面。只需通過它的id找到一個元素,獲取所選元素的索引並獲取所選選項的值。請注意,值將返回你所放置在<option value="..."和字符串比較是大小寫敏感的,所以internet == "no",將無法正常工作,你應該將其更改爲internet == "No"(或更改HTML標記的值)

+0

非常感謝你!正是我想要的!感謝您的評論! :) – 2013-03-04 17:15:05

相關問題