0

我试图在下拉列表中隐藏一个基于特定值的 div,但是我使用的是 rails gem 'simple-form' 这似乎给我带来了麻烦。

    <td><%= f.input :field_type, collection: %w{text_field check_box drop_down}, wrapper_html: { id: 'dropdown' } %>
    <td class="selectobject"><%= f.link_to_add "Add Selection Option", :field_options %>

var form = $('#dropdown');
form.change(function () {
    if ($(this).val() == 'drop_down') {
        $('.selectobject').hide();
    }
    else $('.selectobject').show();
});

When 'drop_down' is selected I want the "selectobject" class to be hidden, so I'm using this jQuery code to hide it, but this doesn't seem to be working. 有什么想法吗?

4

1 回答 1

0

尝试:

var form = $('#dropdown');
form.change(function () {
    var $selected = $(this).find('option:selected');
    if ($selected.val() === 'drop_down') {
        $('.selectobject').hide();
    } else { $('.selectobject').show(); }
});
于 2013-07-12T16:43:34.877 回答