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

时间:2011-11-09 15:29:18

标签: jquery jquery-mobile

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

我想使用jquery移动库。

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

jquery移动框架中是否有任何替代方法可以使用级联下拉列表

2 个答案:

答案 0 :(得分:1)

这样的事情会起作用吗?实例:

HTML

<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

// 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 :(得分:0)

Filament Group有一个光滑的Dropdown / Drilldown菜单:http://filamentgroup.com/lab/jquery_ipod_style_and_flyout_menus/

具体而言,“iPod Style”菜单在移动设备上运行良好。