-5

我正在尝试制作一个专家系统来检测网络问题。用户将有 4 个问题,每个问题有 3 到 4 个答案。用户输入后,用户点击按钮,检测并解决问题。我有点明白了,但我知道缺少一些东西。目前,我只添加了一些随机问题和答案,以检查是否确实有效。请帮助使用 java 脚本,因此它将根据答案提供有关网络问题的详细信息。提前致谢!:)

  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>
4

1 回答 1

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 找到一个元素,获取所选元素的索引并获取所选选项的值。请注意, value 将返回您放置的内容,<option value="..."并且字符串比较区分大小写,因此internet == "no", 将不起作用,您应该将其更改为internet == "No"(或更改 HTML 标记中的值)

于 2013-03-04T17:04:44.857 回答