如何将一个模式中下拉列表中的选定值传递到另一个模式 t 中的另一个下拉列表

How to pass a selected value in a dropdown list in one modal to another dropdown list in another modal t

本文关键字:模式 另一个 下拉列表 值传 一个      更新时间:2023-09-26

我有两个下拉列表,在两种不同的模态中具有相同的值。一个在插入模式中,另一个在更新模式中。我想做的是在插入模式中传递下拉列表的选定值,当我打开更新模式时,我希望在该模式的下拉列表中选择该值。

无论如何我可以做到这一点吗?使用 Bootstrap, jquery, javascript ?

任何帮助将不胜感激。

我试过这个

    var countryInsertID = document.getElementById('countryInsert'), 
        countryUpdate = document.getElementById('countryUpdate'), 
        option; 
        countryInsertID.onchange = function () { 
            option = document.createElement('option'); 
            option.value = this.value; 
            option.text = this.options[this.selectedIndex].text; 
            countryUpdate.appendChild(option); 
            countryInsertID.removeChild(this.options[this.selectedIndex]); 
        }

听起来像是一份localStorage的工作

var countryInsert=document.getElementById('countryInsert')
var countryUpdate=document.getElementById('countryUpdate')
countryInsert.onchange = function() {
    window.localStorage.setItem('selected', countryInsert.value);
}

当您显示更新模式时

countryUpdate.value = window.localStorage.getItem('selected');

更新

如果您只是在同一页面上拥有模态,则隐藏为"引导方式",则不需要所有这些 - 只需

<script>
    var countryInsert=document.getElementById('countryInsert')
    var countryUpdate=document.getElementById('countryUpdate')
    countryInsert.onchange = function() {
        countryUpdate.value = countryInsert.value;
    }
</script>

-- 在页面底部。然后国家/地区更新<select>将始终与国家/地区同步插入<select>

相关文章: