值更改,但视觉表示不会更改

cotxawn7  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(230)

我正在使用select2库,我有以下代码:

$("#brand_id").on('change', function(){
    let brand_id = $("#brand_id").val()
    if(brand_id){
        console.log('changed')
        toggleDisabled($("#bike_situation_id"), false)
        $("#bike_situation_id").val("1").change()
    } else {
        toggleDisabled($("#bike_situation_id"), true)
    }
})

我遇到的问题是 $("#bike_situation_id").val("1").change() . 因为如果我这样做了 console.log($("#bike_situation_)id").val()) 回报是 1 ,但选择框不会更新。
我的html元素:

<div class="container">
                        <label>Marca: <img src="{% static './assets/info.svg' %}" id="info-brand" width="15px"
                                height="15px" /></label>

                        <select name="brand" id="brand_id">
                            <option value="">---------</option>
                        </select>
                        <div id="modal-brand" class="modal">
                            <!-- Modal content -->
                            <div class="modal-content">
                                <span class="close">&times;</span>
                                <p>
                                    Marca do fabricante da bicicleta
                                </p>
                            </div>
                        </div>
                    </div>

                    <div class="container">
                        <label>Sua bike é: <img src="{% static './assets/info.svg' %}" id="info-bike" width="15px"
                                height="15px" /></label>
                        <select name="bike_situation" id="bike_situation_id">
                            <option value="">---------</option>
                            <option value="0">Nova</option>
                            <option value="1">Usada</option>
                        </select>
                        <div id="modal-bike" class="modal">
                            <!-- Modal content -->
                            <div class="modal-content">
                                <span class="close">&times;</span>
                                <p>
                                    Indique se sua bike é nova ou usada!
                                </p>
                                <p>
                                    Consideramos bike Nova todas as bicicletas que tem até <strong>60 (sessenta)</strong> dias decorridos
                                    da data da nota fiscal.
                                </p>
                            </div>
                        </div>
                    </div>

$("#bike_situation_id").select2({disabled: true, minimumResultsForSearch: Infinity});

$("#brand_id").select2({});

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题