Jquery 我的简单JQ脚本切换不起作用

Jquery 我的简单JQ脚本切换不起作用,jquery,html,Jquery,Html,我正在建立一个网站,我有以下问题。当一个用户选择他属于我的大学时,我向他索要他的控制号码,我需要隐藏div institucion_nombre并显示div campos;如果他不属于这所大学,那么我要求他输入他所属大学的名称,也就是说,我想显示div institucion_nombre并隐藏div campos <html> <head> <title>Welcome to website 0.1</title> <meta charse

我正在建立一个网站,我有以下问题。当一个用户选择他属于我的大学时,我向他索要他的控制号码,我需要隐藏div institucion_nombre并显示div campos;如果他不属于这所大学,那么我要求他输入他所属大学的名称,也就是说,我想显示div institucion_nombre并隐藏div campos

<html>
<head>
<title>Welcome to website 0.1</title>
<meta charset="utf-8">
<script> 
     $(function(){
         $("#amIfromThisUniversity_1").on("change",function(){
         $("#institucion_nombre").toggle(this.selectedIndex==1); 
        });
      $("#amIfromThisUniversity_1").change();  
    });
</script>

<script>

   $(function(){
      $("#amIfromThisUniversity_2").on("change",function(){
      $("#institucion_nombre_2").toggle(this.selectedIndex==1);
      });
      $("#amIfromThisUniversity_2").change(); 
  });

</script>
</head>
   <b><h3>Student 1</h3></b>         
        <li> 
        Name* <input id="Field0"  type="text" />
        Middle Name <input id="Field1"  type="text"/>
            Last name <input id="Field2" type="text"  />
        </li>

       <li>Are you student of this university?
             <select name="amIfromThisUniversity_1">                 
                <option  value="1" selected="selected" >Yes</option>
                <option  value="2" >No</option>    
                </select>    
           </li>

           <div id="institucion_nombre">                    
            <li>
            Write your institution's name 
                <input id="Field5" name="institucion_1" type="text"/>
       </li>
      </div><!--Fin del nombre de la institución-->                 

     <div id="campos">     
       <li>
        Student's control number <input id="Field6" name="expediente_1" type="text" />
       </li>                                
        </div><!--fin de los campos-->

   <hr /> <!--separacion-->

   <b><h3>Student 2</h3></b>         
        <li> 
        Name* <input id="Field0" type="text" />
        Middle Name <input id="Field1" type="text"/>
            Last name <input id="Field2" type="text"/>
        </li>

       <li>Are you student of this university?
             <select name="amIfromThisUniversity_2">                 
                <option   value="1"  selected="selected" >Yes</option>
                <option   value="2"  >No</option>      
                 </select>   
           </li>

           <div id="institucion_nombre_2">                  
            <li>
            Write your institution's name 
                <input id="Field5"  type="text"/>
       </li>
      </div><!--Fin del nombre de la institución-->                 

     <div id="campos2">     
       <li>
            Student's control number <input id="Field6" type="text" />
       </li>                                
        </div><!--fin de los campos-->

   <hr /> <!--separacion-->    
</html>
欢迎提出所有建议和意见,并随时修改本手册中的代码: :
干杯

您写错了选择器

<select name="amIfromThisUniversity_1">
您可以用这种方式编写相同的代码

$(function () {
    $("select[name=amIfromThisUniversity_1]").on("change", function () {
        $("#institucion_nombre").toggle(this.selectedIndex == 1);
    }).change();
    
    $("select[name=amIfromThisUniversity_1]").on("change", function () {
        $("#institucion_nombre_2").toggle(this.selectedIndex == 1);
    }).change();
});
此外,李通常被认为是ol或ul的直系子女。将它们替换为div以使HTML有效

如果你的元素是

-ID选择器$AmiFromthis University_1

你的选择器会起作用的

此外,当您尝试在小提琴中复制相同的代码时,您可以只粘贴代码而不粘贴脚本标记。。还需要将框架设置为jQuery

您的标记不正确。。。LI必须在UL或OL中,除LI之外的任何元素都不能是UL或OL的直接子元素。
$(function () {
    $("select[name=amIfromThisUniversity_1]").on("change", function () {
        $("#institucion_nombre").toggle(this.selectedIndex == 1);
    }).change();
    
    $("select[name=amIfromThisUniversity_1]").on("change", function () {
        $("#institucion_nombre_2").toggle(this.selectedIndex == 1);
    }).change();
});