首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery chained选择了我做错了什么的任何线索?

Jquery chained选择了我做错了什么的任何线索?
EN

Stack Overflow用户
提问于 2013-01-08 19:38:04
回答 2查看 126关注 0票数 0

我正在使用data attr进行选择,我想根据第一个select的data属性进行过滤。这是我的代码,请让我知道什么?请原谅我代码的混乱,我是一个javascript/Jquery新手

html块/

代码语言:javascript
复制
<select id="selectOne">
                    <option data-team='{"team":"Engineering"}'>Engineering </option>
                    <option   data-team='{"team": "Software"}'>Software Development</option>
                    <option data-team='{"team": "HumanResources"}'>Human Resources</option>
                    <option  data-team='{"team": "MarkettingAndSales"}'>Marketting and Sales</option>
                    <option  data-team='{"team": "Administrative"}'>Administrative</option>
                    <option  data-team='{"team": "Others"}' class="others">Others</option>
                </select>

                <select id="selectTwo">
                    <option  class="two" data-Speciality='{"team": "Software", "Speciality": "WebDevelopment"}'>Web Development </option>
                    <option  class="two" data-Speciality='{"team": "Engineering", "Speciality": "WebApplication"}'>Application Development </option>
                    <option  class="two" data-Speciality='{"team": "Software", "Speciality": "WebDevelopment"}'>UI/UX Design</option>
                    <option  class="two" data-Speciality='{"team": "Others", "Speciality": "ScientificResearch"}'>Scientific / Research</option>
                    <option  class="two" data-Speciality='{"team": "Engineering", "Speciality": "ScientificResearch"}'>Computer Hardware / Networking</option>
                    <option class="two" data-Speciality='{"team": "Others", "Speciality": "Others"}'>Others</option>
                </select>

$(function(){
    // function to use ajax calls to filter the table data depending on the select forms value
            $("#selectOne").change(function() {
                $("#selectTwo").hide();
                var selected = $(this).find('option:selected');
                $('#selectTwo option [data-team===selected]').show();



            console.log( $(selected).data('team') );

            //the filtering mechanism based on the class
         });

/显然我没有得到第二个select的值为什么?

代码语言:javascript
复制
$(function(){
    // function to use ajax calls to filter the table data depending on the select forms value
        $("#selectOne").change(function() {
    var selected=$(this).find('option:selected').data('team').teamName;
    console.log(selected);
    var selectTwo= $('#selectTwo').val().data('Speciality').team;
     console.log(selectTwo);

})
EN

回答 2

Stack Overflow用户

发布于 2013-01-08 19:42:12

您不能那样显示/隐藏option,至少不能在每个浏览器中显示/隐藏。

你必须主动地操作DOM,比如根据你的过滤器逻辑移除和添加元素,这样你就只能用简单的jQuery把事情搞得一团糟。

如果您需要这样的功能,我会使用任何可以将数据从UI客户端解耦的功能:here you can find许多解决方案。

票数 1
EN

Stack Overflow用户

发布于 2013-01-08 19:43:51

我认为,你想要的是:

代码语言:javascript
复制
var selected = $(this).val();    
$('#selectTwo').val(selected).show();

不确定您所期望的是什么。

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

https://stackoverflow.com/questions/14214122

复制
相关文章

相似问题

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