获取所选项目的值,并在第二个下拉列表中更改列表


get value of selected item and change the list on second dropdown

>当在第一个下拉列表中选择项目时,我正在尝试更改第二个下拉列表

$output_body = '<select>';
$accounts = $service->management_accounts->listManagementAccounts("~all");
  foreach($accounts['items'] as $item) {
 $output_body .= sprintf('<option value="%d">%s</option>', $item['id'], $item['name']);
    }
    $output_body .= '</select>';

因此,当我从上面的下拉列表中选择一个项目时,它应该将所选项目的值存储在变量中,并且该变量将在此处使用,我相信它会更新下拉列表

$webproperties = $service->management_webproperties->listManagementWebproperties("var here");
    foreach($webproperties['items'] as $item) {
        $output_prop .= sprintf('<option value="">%s</option>', $item['name']);
    }
    $output_prop .= '</select>'; 

这是jQuery中级联下拉列表的一个很好的例子。(根据选择另一个填充一个)

<script>
    $(function () {
        var productsSelect = $('#productId');
        productsSelect.attr('disabled', true);
        $('#categoryId').change(function () {
            var categoryId = $(this).val();
            $.getJSON('/GetProducts/' + categoryId, function (products) {
                productsSelect.attr('disabled', false);
                productsSelect.empty();
                productsSelect.append(
                        $('<option/>')
                            .attr('value', '')
                            .text('-- Select Product --'));
                $.each(products, function (index, product) {
                    productsSelect.append(
                        $('<option/>')
                            .attr('value', product.ProductId)
                            .text(product.ProductName)
                    );
                });
            });
        });
    });
</script>
在我看来,

能够将父元素上的事件冒泡与 html 数据元素结合使用,将请求提交到您的 php 控制器并将选项数据分配回您的视图,我会很好,但我不确定您是否有 mvc 框架来支持这一点......

 window.addEvent('domready', function() {
        $('parent_option_list_container').addEvent('click:relay(a)', function(e, ele) {
    if (ele.hasClass('some_option_in_the_list')) {
        e.preventDefault();
        var selected = ele.get('data-option-value');
                    var request = new Request({
        method: 'POST',
        url : '/form_controller/option_select_toggle_function/' + selected,
        }).send();
    }

}

相关文章: