首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用jquery mobile构建一个级联下拉列表?

如何使用jquery mobile构建一个级联下拉列表?
EN

Stack Overflow用户
提问于 2011-11-09 23:29:18
回答 2查看 7.1K关注 0票数 1

我有一个表单,我将在应用程序中使用两个级联下拉列表和几个文本框。

我想使用jquery移动库。

如何构建级联下拉列表?因为如果您使用jquery mobile,它会用带有ul、li和很多div的选项覆盖dropdowlist。

在jquery mobile framework中有没有使用级联下拉列表的替代方案?

EN

回答 2

Stack Overflow用户

发布于 2011-11-10 01:19:09

像这样的东西可以工作吗?现场示例:

HTML

代码语言:javascript
复制
<div data-role="page" id="home">
    <div data-role="content">

        <form name="test">
            <select name="state_select" id="state_select">
                <option value="">Select a state</option>
            </select>

            <select name="city_select" id="city_select">
                <option value="">Select a City</option>
            </select>

            <select name="theater_select" id="theater_select">
                <option value="">Select a Theater</option>
            </select>

        </form>

    </div>
</div>

JS

代码语言:javascript
复制
// Add State Options
for (i = 0; i <= 50; i++) {
    $('#state_select').append('<option value="state' + i + '">State ' + i + '</option>');
    $('#state_select_show').append('<option value="state' + i + '">State ' + i + '</option>');
}

addCites();
addTheaters();

$("#city_select").parent().parent().hide();
$("#theater_select").parent().parent().hide();

function addCites() {
    ii = 0;

    for (i = 0; i <= 500; i++) {
        if ((i % 10) == 0) {
            ii++;
        }
        $('#city_select').append('<option value="city' + i + '" id="state' + ii + '">City ' + i + '</option>');
        $('#city_select_show').append('<option value="city' + i + '" id="state' + ii + '">City ' + i + '</option>');
    }
}

function addTheaters() {
    ii = 0;

    for (i = 0; i <= 1000; i++) {
        if ((i % 10) == 0) {
            ii++;
        }
        $('#theater_select').append('<option value="theater' + i + '" id="city' + ii + '">Theater ' + i + '</option>');
        $('#theater_select_show').append('<option value="theater' + i + '" id="city' + ii + '">Theater ' + i + '</option>');
    }
}

$('#state_select').change(function() {
    var selectedState = $(this).val();
    var selectFirst = 0;
    addCites();

    $("#city_select option").each(function() {
        if ($(this).attr('id') != selectedState) {
            $(this).remove();
        } else {
            if (selectFirst < 1) {
                $(this).attr('id', selectedState).attr('selected', 'selected');
            }
            selectFirst++;
        }
    });
    $("#city_select").parent().parent().show();

    if ($('#city_select option').size() == 0) {
        $('#city_select').append('<option value="nocity">No City Found</option>');
    }
});

$('#city_select').change(function() {
    var selectedCity = $(this).val();
    var selectFirst = 0;
    addTheaters();

    $("#theater_select option").each(function() {
        if ($(this).attr('id') != selectedCity) {
            $(this).remove();
        } else {
            if (selectFirst < 1) {
                $(this).attr('id', selectedCity).attr('selected', 'selected');
            }
            selectFirst++;
        }
    });
    $("#theater_select").parent().parent().show();

    if ($('#theater_select option').size() == 0) {
        $('#theater_select').append('<option value="notheater">No Theater Found Near You</option>');
    }
});
票数 1
EN

Stack Overflow用户

发布于 2011-11-10 01:28:35

灯丝组有一个灵活的下拉/下拉菜单:http://filamentgroup.com/lab/jquery_ipod_style_and_flyout_menus/

特别是"iPod Style“菜单在移动设备上工作得很好。

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

https://stackoverflow.com/questions/8067280

复制
相关文章

相似问题

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