Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript selectbox Else If语句_Javascript_Html - Fatal编程技术网

Javascript selectbox Else If语句

Javascript selectbox Else If语句,javascript,html,Javascript,Html,这是我的JS代码 <script type="text/javascript"> function showfield6(name){ if(name=='Other') document.getElementById('div6').innerHTML='Other: <input type="text" name="pubfer" />'; else document.getElementById('div6').inner

这是我的JS代码

<script type="text/javascript">
  function showfield6(name){
    if(name=='Other')
      document.getElementById('div6').innerHTML='Other: <input type="text" name="pubfer" />';
    else
      document.getElementById('div6').innerHTML='';
  }
</script>
如果用户选择“样本”,则打开“骨骼、牙齿、头发”字段。如果用户选择“骨骼”,将打开新的文本字段。它们的名称是“side,elements”等。如果用户选择“齿”,将打开新的文本字段


如何创建此表单?

似乎是一个学术问题,否则就不会出现“不能使用else if语句”的情况。因此,我能给您的唯一解决方案是研究switch case语句

**编辑:在@Stano注释之后,下面是关于如何使用switch case语句的更多细节

当一个变量有多个可能的值并且希望基于该值执行代码时,可以使用Switch case

例如,您的showfield6()函数可以如下所示:

function showfield6(id) {

  switch(id) {  //Begin swith case
    case "Bone":    //When id=="Bone"
      //Execute code block here
      break;        //If you do not add this break, the code in the next case will be executed
    case "Teeth":   //When id=="Teeth"
      //Execute code for "Teeth"
      break;
    case "Hair": 
      //Code block
      break;
    case default:   //Anything that wasnt't matched aboved (id=="SomethingElse")
      //Handle other cases here
  }

}
有关swith案例陈述的更多信息:

是的,也许它肯定会对你有帮助。看看这个

http://www.w3schools.com/js/js_switch.asp

-谢谢

“我不能使用else if语句…”为什么不呢?顺便说一句,标题不是用来键入标签的。哦,为什么要给php加标签?您的代码与示例不匹配。请给出一个与您的代码相关的示例。或者更新你的代码。好的观点@Stano,刚刚用更多细节编辑了我的答案。。。我想我太懒了,因为我还没有喝第一杯咖啡P
function showfield6(id) {

  switch(id) {  //Begin swith case
    case "Bone":    //When id=="Bone"
      //Execute code block here
      break;        //If you do not add this break, the code in the next case will be executed
    case "Teeth":   //When id=="Teeth"
      //Execute code for "Teeth"
      break;
    case "Hair": 
      //Code block
      break;
    case default:   //Anything that wasnt't matched aboved (id=="SomethingElse")
      //Handle other cases here
  }

}
http://www.w3schools.com/js/js_switch.asp