繁体   English   中英

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

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

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

反正我能做到吗? 使用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>

-在页面底部。 然后countryUpdate <select>将始终与countryInsert <select>同步

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM