javascript - 下拉选择更改

标签 javascript jquery html

我有一个下拉菜单,应该可以更改我页面上的功能,但显然不起作用。一旦用户选择并且行业更新 map 并且应该更新下面的图例,我就会在下拉选择中有一张 map 。图例未更新

请指出我做错了什么。

谢谢

JS

    $("#lstMap1Occ").change(function () {
        var index = $(this).children(":selected").index();
        $("#legend").children().hide().eq(index).show();
    });

这是下拉列表(是的,有一个结束选择标签只是因为一些奇怪的原因没有粘贴)

<select id="lstMap1Occ">
    <option value="1">Engineers </option>
    <option value="2">Chemical Engineers</option>
</select>

HTML

<div class="legend">
<div class="engineers">
    <ul>
        <li style="background-color:rgb(254,240,217);">0-345</li>
        <li style="background-color:rgb(253,212,158);">346-503</li>
        <li style="background-color:rgb(253,187,132);">504-1240</li>
        <li style="background-color:rgb(252,141,89);">1241-1679</li>
        <li style="background-color:rgb(239,101,72);">1680-2625</li>
        <li style="background-color:rgb(215,48,31);">2627-4789</li>
    </ul>
</div>
<div class="chemical"> 
    <ul>
        <li style="background-color:rgb(254,240,217);">0-13</li>
        <li style="background-color:rgb(253,212,158);">14-24</li>
        <li style="background-color:rgb(253,187,132);">25-37</li>
        <li style="background-color:rgb(252,141,89);">38-56</li>
        <li style="background-color:rgb(239,101,72);">57-112</li>
        <li style="background-color:rgb(215,48,31);">113-168</li>
    </ul>
</div>

最佳答案

.legend 不是#legend http://jsfiddle.net/fy6hf/1/

$("#lstMap1Occ").change(function () {
        var index = $(this).children(":selected").index();
        $(".legend").children().hide().eq(index).show();
    });

关于javascript - 下拉选择更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17600354/

相关文章:

javascript - jQuery - 数组元素作为选择器

javascript - Grunt 构建 useminprepare 不起作用

javascript - Ag-Grid:如何保存和重新加载列顺序

javascript - Heroku nuxt 生产部署使用暂存配置变量

javascript - 使用 Bootstrap CSS 我想显示正确的移动 View

php - 强制页面从服务器重新加载而不是加载缓存版本

javascript - 使用 jquery 动态创建下拉菜单不起作用

javascript - 如何访问嵌套的 json 对象并使用 javascript 动态显示?

php - 尝试使用 HTML DOM 解析器获取亚马逊页面上的主要图像

javascript - (JavaScript/HTML) 如何更改按钮单击时样式属性的显示?