最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Dropdown clear option semantic-ui - Stack Overflow

programmeradmin3浏览0评论

I've encountered a problem when trying to implement 2 dropdowns in semantic-ui.

What I want to happen is that when I change the selected item in the first dropdown the second dropdown will be automatically be cleared from its pervious selection (this is the first step in implementing an automatic change to the content of the second dropdown).

I've created a simpler version containing 2 dropdowns and a clear button in JS bin : here.

The code:

var $one = $('#one'),
    $two = $('#two');

$two.dropdown();
$one.dropdown({
    onChange :function(val) {
        $two.dropdown('clear');
    }
});

$('.button').on('click', function() {
    $('#two').dropdown('clear');  
});

Here I've encountered multiple problems:

The first problem I encountered was that the clear button won't clear both dropdowns unless both dropdowns are only initialised and no other settings added in the initialisation (i.e $(".ui.dropdown").dropdown()).

The second problem is that in the provided code the a dropdown will be cleared (only the second dropdown will be cleared for some reason, and not the first) only if the selector for the clear button will be $(".ui.dropdown) , if I use $("#one")/$("#two") the button won't clear the dropdown.

And the third problem , is that when a change occurs in the first dropdown the second dropdown is not being cleared , which is my ultimate goal.

Any thoughts or suggestions will be greatly appreciated.

I've encountered a problem when trying to implement 2 dropdowns in semantic-ui.

What I want to happen is that when I change the selected item in the first dropdown the second dropdown will be automatically be cleared from its pervious selection (this is the first step in implementing an automatic change to the content of the second dropdown).

I've created a simpler version containing 2 dropdowns and a clear button in JS bin : here.

The code:

var $one = $('#one'),
    $two = $('#two');

$two.dropdown();
$one.dropdown({
    onChange :function(val) {
        $two.dropdown('clear');
    }
});

$('.button').on('click', function() {
    $('#two').dropdown('clear');  
});

Here I've encountered multiple problems:

The first problem I encountered was that the clear button won't clear both dropdowns unless both dropdowns are only initialised and no other settings added in the initialisation (i.e $(".ui.dropdown").dropdown()).

The second problem is that in the provided code the a dropdown will be cleared (only the second dropdown will be cleared for some reason, and not the first) only if the selector for the clear button will be $(".ui.dropdown) , if I use $("#one")/$("#two") the button won't clear the dropdown.

And the third problem , is that when a change occurs in the first dropdown the second dropdown is not being cleared , which is my ultimate goal.

Any thoughts or suggestions will be greatly appreciated.

Share Improve this question edited Jun 10, 2020 at 6:29 braX 11.8k5 gold badges22 silver badges37 bronze badges asked Aug 27, 2015 at 14:00 user3040942user3040942 811 gold badge1 silver badge4 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 9
$(document).ready(function () {
            $("#super_type").dropdown({
                onChange: function (val) {
                    $('#subtype_list').dropdown('clear');
     });
});

This is the best and easy solution provided by semantic UI. $('.ui.dropdown').dropdown({ "clearable": true }); By default the value of clearable setting is false.

See http://semantic-ui./modules/dropdown.html#behavior

$('.your.element').dropdown('set selected', "value");

This worked for me.

Using only js/jquery

var elemento = $("idElementoSelect).next().next();
elemento.html('text';)

see http://www.semantic-ui.cn/modules/dropdown.html#/settings

$('select.dropdown').dropdown({placeholder:''});
发布评论

评论列表(0)

  1. 暂无评论