0

2 つの異なるモーダルに同じ値を持つ 2 つのドロップダウン リストがあります。1 つは Insert モーダルにあり、もう 1 つは Update モーダルにあります。私がしたいのは、ドロップダウン リストの選択した値を挿入モーダルに渡すことです。更新モーダルを開くと、そのモーダルのドロップダウン リストでその値が選択されます。

とにかく私はこれを行うことができますか?ブートストラップ、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]); 
        }
4

1 に答える 1

0

の仕事のようですね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>

于 2013-10-23T13:13:46.087 に答える