首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置单击复选框时设置下拉菜单集?

如何设置单击复选框时设置下拉菜单集?
EN

Stack Overflow用户
提问于 2015-05-12 13:47:51
回答 4查看 835关注 0票数 1

我想设置下拉菜单。当我点击复选框物理,然后打开子类别。否则就不会open.Here a一些代码..我想在表格中设置这个菜单,其中一个可以帮助me..tell我如何设置jquery。

代码语言:javascript
复制
<table >
<tr>
        <td valign="top">Disciplines :</td>
        <td><table>
            <tr>
            
         <td width="30"><input type="checkbox" name="Physics" /></td>
              <td width="200">Physics
              <table style="display:none;">
            <tr>
              <td width="30"><input type="checkbox" name="Acoustics" /></td>
              <td width="200">Acoustics</td>
               </tr>
                  <tr>
              <td width="30"><input type="checkbox" name="Cosmology" /></td>
              <td width="200">Cosmology</td>
               </tr>
                  <tr>
              <td width="30"><input type="checkbox" name="Nuclear Physics" /></td>
              <td width="200">Nuclear Physics</td>
               </tr>
          </table>
                    
                    <td width="30"><input type="checkbox" name="Chemistry" /></td>
              <td width="200">Chemistry
              <table style="display:none;">
            <tr>
              <td width="30"><input type="checkbox" name="Chromatography" /></td>
              <td width="200">Chromatography</td>
               </tr>
                  <tr>
              <td width="30"><input type="checkbox" name="Catalysis" /></td>
              <td width="200">Catalysis</td>
               </tr>
                  <tr>
              <td width="30"><input type="checkbox" name="Geochemistry" /></td>
              <td width="200">Geochemistry</td>
                    </tr>
          </table>
               </tr>
          </table>
              </td>
                
                </tr>
                
            
          
            
          </table>  
          </td>
      </tr>
</table>

EN

回答 4

Stack Overflow用户

发布于 2015-05-12 14:00:55

我希望这对你有用。

代码语言:javascript
复制
$('input[name="Physics"]').on('click', function() {
    $('.physicsTable').slideToggle();
})

$('input[name="Chemistry"]').on('click', function() {
    $('.cheTable').slideToggle();
})
票数 3
EN

Stack Overflow用户

发布于 2015-05-12 14:04:11

试试这个:

代码语言:javascript
复制
$('input[name=Physics], input[name=Chemistry]').on('click', function(){
  if($(this).is(':checked')){
       $(this).parent().next().find('table').show();
  }else{
        $(this).parent().next().find('table').hide();
    }
 
});
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr>
    <td valign="top">Disciplines :</td>
    <td>
      <table>
        <tr>

          <td width="30">
            <input type="checkbox" name="Physics" />
          </td>
          <td width="200">Physics
            <table style="display:none;">
              <tr>
                <td width="30">
                  <input type="checkbox" name="Acoustics" />
                </td>
                <td width="200">Acoustics</td>
              </tr>
              <tr>
                <td width="30">
                  <input type="checkbox" name="Cosmology" />
                </td>
                <td width="200">Cosmology</td>
              </tr>
              <tr>
                <td width="30">
                  <input type="checkbox" name="Nuclear Physics" />
                </td>
                <td width="200">Nuclear Physics</td>
              </tr>
            </table>

            <td width="30">
              <input type="checkbox" name="Chemistry" />
            </td>
            <td width="200">Chemistry
              <table style="display:none;">
                <tr>
                  <td width="30">
                    <input type="checkbox" name="Chromatography" />
                  </td>
                  <td width="200">Chromatography</td>
                </tr>
                <tr>
                  <td width="30">
                    <input type="checkbox" name="Catalysis" />
                  </td>
                  <td width="200">Catalysis</td>
                </tr>
                <tr>
                  <td width="30">
                    <input type="checkbox" name="Geochemistry" />
                  </td>
                  <td width="200">Geochemistry</td>
                </tr>
              </table>
        </tr>
      </table>
      </td>

  </tr>




</table>
</td>
</tr>
</table>

票数 1
EN

Stack Overflow用户

发布于 2015-05-12 14:26:53

我已经稍微修改了你的代码和PFB的源代码,希望它能有所帮助

HTML

代码语言:javascript
复制
function showhidetables(value) {


  if (value == "1") {
    document.getElementById('phisycs').style.display = "table";
    document.getElementById('Chemistry').style.display = "none";
    document.getElementById("PhysicsCheck").checked = true;
    document.getElementById("ChemistryCheck").checked = false;
  }
  if (value == "2") {
    document.getElementById('phisycs').style.display = "none";
    document.getElementById('Chemistry').style.display = "table";
    document.getElementById("PhysicsCheck").checked = false;
    document.getElementById("ChemistryCheck").checked = true;
  }
}
代码语言:javascript
复制
<table>
  <tr>
    <td valign="top">Disciplines :</td>
    <td>
      <table>
        <tr>

          <td width="30">
            <input type="checkbox" id="PhysicsCheck" name="Physics" onClick="showhidetables('1')" />
          </td>
          <td width="200">Physics
            <table id="phisycs" style="display: none;">
              <tr>
                <td width="30">
                  <input type="checkbox" name="Acoustics" />
                </td>
                <td width="200">Acoustics</td>
              </tr>
              <tr>
                <td width="30">
                  <input type="checkbox" name="Cosmology" />
                </td>
                <td width="200">Cosmology</td>
              </tr>
              <tr>
                <td width="30">
                  <input type="checkbox" name="Nuclear Physics" />
                </td>
                <td width="200">Nuclear Physics</td>
              </tr>
            </table>
            <td width="30">
              <input type="checkbox" name="Chemistry" id="ChemistryCheck" onClick="showhidetables('2')" />
            </td>
            <td width="200">Chemistry
              <table style="display: none;" id="Chemistry">
                <tr>
                  <td width="30">
                    <input type="checkbox" name="Chromatography" />
                  </td>
                  <td width="200">Chromatography</td>
                </tr>
                <tr>
                  <td width="30">
                    <input type="checkbox" name="Catalysis" />
                  </td>
                  <td width="200">Catalysis</td>
                </tr>
                <tr>
                  <td width="30">
                    <input type="checkbox" name="Geochemistry" />
                  </td>
                  <td width="200">Geochemistry</td>
                </tr>
              </table>
        </tr>
      </table>
      </td>

  </tr>
</table>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30182725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档