【问题标题】:How to pass a selected value in a dropdown list in one modal to another dropdown list in another modal t如何将一个模式中的下拉列表中的选定值传递给另一个模式中的另一个下拉列表
【发布时间】:2013-10-23 11:44:22
【问题描述】:

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

有没有我可以做到这一点?使用 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]); 
        }

【问题讨论】:

  • 请告诉我们你到目前为止所做的尝试:)
  • 我已经尝试使用这个问题的解决方案stackoverflow.com/questions/13911011/…
  • 此外,输入类型中的所有其他值都可以正常传递,我只能传递下拉列表的值。

标签: javascript jquery twitter-bootstrap


【解决方案1】:

听起来像是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 &lt;select&gt; 将始终与 countryInsert &lt;select&gt; 同步

【讨论】:

  • 看起来可能是这样。您能否更具体地说明我应该在哪里放置哪个变量和函数。因为我有两种不同的模式,而 countryInsert id 位于插入模式中,而 countryUpdate id 位于更新模式中。如果这是一个愚蠢的请求,我很抱歉,我只是编程世界的新手,这会很有帮助。
  • 我认为它们都位于同一页面上?在隐藏的
    中?我想到了“标准”引导方式来做到这一点......?当你关闭它们时,模态内容会被破坏吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多