简体   繁体   English

在第一个下拉菜单被选中后显示第二个下拉菜单的内容。

[英]Show content of 2nd Drop down after 1st Drop down getting selected.

I've managed to get one drop-down list to populate the second drop-down list based on the selection. 我设法得到一个下拉列表,以根据选择填充第二个下拉列表。

HTML here: 此处的HTML:

    <select size="1" id="BodyPart" title="" name="BodyPart">
<option value="">-Select Body Part-</option>
<option value="chest">Chest</option>
<option value="biceps">Biceps</option>
</select>

<div class="container">

<div class="chest">
<select class="exercise_select">
<option value ="__select__">SELECT</option>
<option value ="chestpress">Chest Press</option>
<option value ="inclinechestpress">Incline Chest Press</option>
</select>


<div class="chest">
<div class="chestpress exercise_name">
CHEST PRESS
</div>
<div class="inclinechestpress exercise_name">
INCLINE CHEST PRESS    
</div>
</div>
</div>

<div class="biceps">
<select class="exercise_select">
<option value ="__select__">SELECT</option>
<option value="bicepcurls">Bicep Curls</option>
<option value="hammercurls">Hammer Curls</option>
</select>

<div class="biceps">
<div class="bicepcurls exercise_name">
BICEP CURLS
</div>
<div class="hammercurls exercise_name">
HAMMER CURLS   
</div>
</div>
</div>

JavaScript here: JavaScript在这里:

<Script language='JavaScript'>
$(document).ready(function() {
    var elements = $('div.container').children().hide();
    $('#BodyPart').change(function() {
        elements.hide();
        var value = $(this).val();
        if (value.length) { // if somethings' selected
            elements.filter('.' + value).show(); // show the ones we want
    }
});

    $('.exercise_select').change(function(){
        console.log(123);
        $('.exercise_name').hide();
        var subele=$('.exercise_name');
        subele.filter('.'+$(this).val()).show();
    });
});
</script>

As you can see, when 'Chest' or 'Biceps' is selected, relative exercises to that body part becomes available to choose in the second drop-down list. 如您所见,当选择“胸部”或“二头肌”时,可以在第二个下拉列表中选择与该身体部位有关的相对运动。 I want to display information specific to that second selection (as you can see I've used the exercise's title in capitals for dummy text), but for some reason everything displays UNTIL a second option is selected. 我想显示特定于第二个选择的信息(如您所见,我已经使用练习标题用大写字母作为伪文本),但是由于某些原因,所有内容都会显示,直到选择了第二个选项。

So for example, I'd choose 'Chest', then before I select any of the two exercises in the second drop-down list, both dummy texts appear. 因此,例如,我选择“胸”,然后在第二个下拉列表中选择两个练习中的任何一个之前,两个虚拟文本都会出现。 They only single out once I choose the exercise. 他们只有在我选择练习后才会选择。 Is there a way to have those dummy texts remain invisible until one of the options is selected? 有没有一种方法可以使那些伪文本在选择其中一个选项之前保持不可见?

Many thanks for your time. 非常感谢您的宝贵时间。

Include $('.exercise_name').hide(); 包括$('.exercise_name').hide(); in first dropdown change event 在第一个下拉更改事件中

$('#BodyPart').change(function() {
    elements.hide();
    var value = $(this).val();
    if (value.length) { // if somethings' selected
        elements.filter('.' + value).show(); // show the ones we want
}
    $('.exercise_name').hide();
});

Demo 演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想做一个条件,如果我从第一个下拉列表中选择这个项目,它会只显示我在第二个下拉列表中选择的项目 - I want to make a condition in which if I select this item from 1st drop down show it shows me only selected items in 2nd drop down 通过在codeigniter php中使用ajax,根据第一个下拉结果填充第二个下拉列表 - populate 2nd drop down based on 1st drop down result by using ajax in codeigniter php 与第二下拉选择相关的第二下拉选择 - 2nd Drop Down selection to be related to the selection on the 1st Drop Down Selection 如何根据第一个下拉值使第二个下拉列表自动选择值 - How to make 2nd drop down list auto select value based on 1st drop down value 如何根据第一个下拉列表过滤第二个下拉列表 - how to filter 2nd drop-down list according to 1st drop-down list 如何在第一个选择上禁用(或更改颜色)第二个下拉选项? - How to disable (or change color) of 2nd drop down option depenging on 1st selection? Angular JS-1链接到2st链接到3rd。 现在,我需要从第3个下拉列表中选择数据,以便在另一个文本区域中显示 - Angular JS- 1st Dropdown linked to 2nd linked to 3rd. Now I need selected data from 3rd drop down to display in another textarea 下拉菜单:如何取消激活第一个(选定)选项? - drop down menu: how to make deactivate the 1st (selected) option? 显示基于First Drop Down PHP JS的第二个下拉列表 - Show 2nd Dropdown based on First Drop Down PHP JS Cacading Drop Down 2nd Dropdown名称没有得到更改angularjs? - Cacading Drop Down 2nd Dropdown name Not getting Change in angularjs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM